| 320 | #define LEVELS2 10 /* size of the second part of the stack */ |
| 321 | |
| 322 | static int db_errorfb (lua_State *L) { |
| 323 | int level; |
| 324 | int firstpart = 1; /* still before eventual `...' */ |
| 325 | int arg; |
| 326 | lua_State *L1 = getthread(L, &arg); |
| 327 | lua_Debug ar; |
| 328 | if (lua_isnumber(L, arg+2)) { |
| 329 | level = (int)lua_tointeger(L, arg+2); |
| 330 | lua_pop(L, 1); |
| 331 | } |
| 332 | else |
| 333 | level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ |
| 334 | if (lua_gettop(L) == arg) |
| 335 | lua_pushliteral(L, ""); |
| 336 | else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ |
| 337 | else lua_pushliteral(L, "\n"); |
| 338 | lua_pushliteral(L, "stack traceback:"); |
| 339 | while (lua_getstack(L1, level++, &ar)) { |
| 340 | if (level > LEVELS1 && firstpart) { |
| 341 | /* no more than `LEVELS2' more levels? */ |
| 342 | if (!lua_getstack(L1, level+LEVELS2, &ar)) |
| 343 | level--; /* keep going */ |
| 344 | else { |
| 345 | lua_pushliteral(L, "\n\t..."); /* too many levels */ |
| 346 | while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ |
| 347 | level++; |
| 348 | } |
| 349 | firstpart = 0; |
| 350 | continue; |
| 351 | } |
| 352 | lua_pushliteral(L, "\n\t"); |
| 353 | lua_getinfo(L1, "Snl", &ar); |
| 354 | lua_pushfstring(L, "%s:", ar.short_src); |
| 355 | if (ar.currentline > 0) |
| 356 | lua_pushfstring(L, "%d:", ar.currentline); |
| 357 | if (*ar.namewhat != '\0') /* is there a name? */ |
| 358 | lua_pushfstring(L, " in function " LUA_QS, ar.name); |
| 359 | else { |
| 360 | if (*ar.what == 'm') /* main? */ |
| 361 | lua_pushfstring(L, " in main chunk"); |
| 362 | else if (*ar.what == 'C' || *ar.what == 't') |
| 363 | lua_pushliteral(L, " ?"); /* C function or tail call */ |
| 364 | else |
| 365 | lua_pushfstring(L, " in function <%s:%d>", |
| 366 | ar.short_src, ar.linedefined); |
| 367 | } |
| 368 | lua_concat(L, lua_gettop(L) - arg); |
| 369 | } |
| 370 | lua_concat(L, lua_gettop(L) - arg); |
| 371 | return 1; |
| 372 | } |
| 373 | |
| 374 | |
| 375 | static const luaL_Reg dblib[] = { |
nothing calls this directly
no test coverage detected