diff options
Diffstat (limited to 'src/lib_debug.c')
-rw-r--r-- | src/lib_debug.c | 50 |
1 files changed, 4 insertions, 46 deletions
diff --git a/src/lib_debug.c b/src/lib_debug.c index 07b025af..06750266 100644 --- a/src/lib_debug.c +++ b/src/lib_debug.c | |||
@@ -383,55 +383,13 @@ LJLIB_CF(debug_debug) | |||
383 | 383 | ||
384 | LJLIB_CF(debug_traceback) | 384 | LJLIB_CF(debug_traceback) |
385 | { | 385 | { |
386 | int level; | ||
387 | int firstpart = 1; /* still before eventual `...' */ | ||
388 | int arg; | 386 | int arg; |
389 | lua_State *L1 = getthread(L, &arg); | 387 | lua_State *L1 = getthread(L, &arg); |
390 | lua_Debug ar; | 388 | const char *msg = lua_tostring(L, arg+1); |
391 | if (lua_isnumber(L, arg+2)) { | 389 | if (msg == NULL && L->top > L->base+arg) |
392 | level = (int)lua_tointeger(L, arg+2); | 390 | L->top = L->base+arg+1; |
393 | lua_pop(L, 1); | ||
394 | } | ||
395 | else | 391 | else |
396 | level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ | 392 | luaL_traceback(L, L1, msg, lj_lib_optint(L, arg+2, (L == L1))); |
397 | if (lua_gettop(L) == arg) | ||
398 | lua_pushliteral(L, ""); | ||
399 | else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ | ||
400 | else lua_pushliteral(L, "\n"); | ||
401 | lua_pushliteral(L, "stack traceback:"); | ||
402 | while (lua_getstack(L1, level++, &ar)) { | ||
403 | if (level > LEVELS1 && firstpart) { | ||
404 | /* no more than `LEVELS2' more levels? */ | ||
405 | if (!lua_getstack(L1, level+LEVELS2, &ar)) { | ||
406 | level--; /* keep going */ | ||
407 | } else { | ||
408 | lua_pushliteral(L, "\n\t..."); /* too many levels */ | ||
409 | /* This only works with LuaJIT 2.x. Avoids O(n^2) behaviour. */ | ||
410 | lua_getstack(L1, -10, &ar); | ||
411 | level = ar.i_ci - LEVELS2; | ||
412 | } | ||
413 | firstpart = 0; | ||
414 | continue; | ||
415 | } | ||
416 | lua_pushliteral(L, "\n\t"); | ||
417 | lua_getinfo(L1, "Snl", &ar); | ||
418 | lua_pushfstring(L, "%s:", ar.short_src); | ||
419 | if (ar.currentline > 0) | ||
420 | lua_pushfstring(L, "%d:", ar.currentline); | ||
421 | if (*ar.namewhat != '\0') { /* is there a name? */ | ||
422 | lua_pushfstring(L, " in function " LUA_QS, ar.name); | ||
423 | } else { | ||
424 | if (*ar.what == 'm') /* main? */ | ||
425 | lua_pushfstring(L, " in main chunk"); | ||
426 | else if (*ar.what == 'C' || *ar.what == 't') | ||
427 | lua_pushliteral(L, " ?"); /* C function or tail call */ | ||
428 | else | ||
429 | lua_pushfstring(L, " in function <%s:%d>", | ||
430 | ar.short_src, ar.linedefined); | ||
431 | } | ||
432 | lua_concat(L, lua_gettop(L) - arg); | ||
433 | } | ||
434 | lua_concat(L, lua_gettop(L) - arg); | ||
435 | return 1; | 393 | return 1; |
436 | } | 394 | } |
437 | 395 | ||