aboutsummaryrefslogtreecommitdiff
path: root/ldblib.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldblib.c')
-rw-r--r--ldblib.c51
1 files changed, 6 insertions, 45 deletions
diff --git a/ldblib.c b/ldblib.c
index d8224a8e..6a574187 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.105 2006/09/11 14:07:24 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.106 2007/04/26 20:39:38 roberto Exp roberto $
3** Interface from Lua to its debug API 3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -315,55 +315,16 @@ static int db_debug (lua_State *L) {
315} 315}
316 316
317 317
318#define LEVELS1 12 /* size of the first part of the stack */
319#define LEVELS2 10 /* size of the second part of the stack */
320
321static int db_errorfb (lua_State *L) { 318static int db_errorfb (lua_State *L) {
322 lua_Debug ar;
323 int firstpart = 1; /* still before eventual `...' */
324 int arg; 319 int arg;
325 lua_State *L1 = getthread(L, &arg); 320 lua_State *L1 = getthread(L, &arg);
326 const char *msg = lua_tostring(L, arg + 1); 321 const char *msg = lua_tostring(L, arg + 1);
327 int level = (lua_isnumber(L, arg + 2)) ? 322 if (msg == NULL && !lua_isnoneornil(L, arg + 1)) /* non-string 'msg'? */
328 (int)lua_tointeger(L, arg + 2) : 323 lua_pushvalue(L, arg + 1); /* return it untouched */
329 (L == L1) ? 1 : 0; /* level 0 may be this own function */ 324 else {
330 lua_settop(L, ++arg); 325 int level = luaL_optint(L, arg + 2, (L == L1) ? 1 : 0);
331 if (msg) lua_pushfstring(L, "%s\n", msg); 326 luaL_traceback(L, L1, msg, level);
332 else if (!lua_isnil(L, arg)) /* is there a non-string 'msg'? */
333 return 1; /* return it untouched */
334 lua_pushliteral(L, "stack traceback:");
335 while (lua_getstack(L1, level++, &ar)) {
336 if (level > LEVELS1 && firstpart) {
337 /* no more than `LEVELS2' more levels? */
338 if (!lua_getstack(L1, level+LEVELS2, &ar))
339 level--; /* keep going */
340 else {
341 lua_pushliteral(L, "\n\t..."); /* too many levels */
342 while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */
343 level++;
344 }
345 firstpart = 0;
346 continue;
347 }
348 lua_pushliteral(L, "\n\t");
349 lua_getinfo(L1, "Snl", &ar);
350 lua_pushfstring(L, "%s:", ar.short_src);
351 if (ar.currentline > 0)
352 lua_pushfstring(L, "%d:", ar.currentline);
353 if (*ar.namewhat != '\0') /* is there a name? */
354 lua_pushfstring(L, " in function " LUA_QS, ar.name);
355 else {
356 if (*ar.what == 'm') /* main? */
357 lua_pushfstring(L, " in main chunk");
358 else if (*ar.what == 'C' || *ar.what == 't')
359 lua_pushliteral(L, " ?"); /* C function or tail call */
360 else
361 lua_pushfstring(L, " in function <%s:%d>",
362 ar.short_src, ar.linedefined);
363 }
364 lua_concat(L, lua_gettop(L) - arg);
365 } 327 }
366 lua_concat(L, lua_gettop(L) - arg);
367 return 1; 328 return 1;
368} 329}
369 330