| 11836 | #define LEVELS2 10 /* size of the second part of the stack */ |
| 11837 | |
| 11838 | static int db_errorfb (lua_State *L) { |
| 11839 | int level; |
| 11840 | int firstpart = 1; /* still before eventual `...' */ |
| 11841 | int arg; |
| 11842 | lua_State *L1 = getthread(L, &arg); |
| 11843 | lua_Debug ar; |
| 11844 | if (lua_isnumber(L, arg+2)) { |
| 11845 | level = (int)lua_tointeger(L, arg+2); |
| 11846 | lua_pop(L, 1); |
| 11847 | } |
| 11848 | else |
| 11849 | level = (L == L1) ? 1 : 0; /* level 0 may be this own function */ |
| 11850 | if (lua_gettop(L) == arg) |
| 11851 | lua_pushliteral(L, ""); |
| 11852 | else if (!lua_isstring(L, arg+1)) return 1; /* message is not a string */ |
| 11853 | else lua_pushliteral(L, "\n"); |
| 11854 | lua_pushliteral(L, "stack traceback:"); |
| 11855 | while (lua_getstack(L1, level++, &ar)) { |
| 11856 | if (level > LEVELS1 && firstpart) { |
| 11857 | /* no more than `LEVELS2' more levels? */ |
| 11858 | if (!lua_getstack(L1, level+LEVELS2, &ar)) |
| 11859 | level--; /* keep going */ |
| 11860 | else { |
| 11861 | lua_pushliteral(L, "\n\t..."); /* too many levels */ |
| 11862 | while (lua_getstack(L1, level+LEVELS2, &ar)) /* find last levels */ |
| 11863 | level++; |
| 11864 | } |
| 11865 | firstpart = 0; |
| 11866 | continue; |
| 11867 | } |
| 11868 | lua_pushliteral(L, "\n\t"); |
| 11869 | lua_getinfo(L1, "Snl", &ar); |
| 11870 | lua_pushfstring(L, "%s:", ar.short_src); |
| 11871 | if (ar.currentline > 0) |
| 11872 | lua_pushfstring(L, "%d:", ar.currentline); |
| 11873 | if (*ar.namewhat != '\0') /* is there a name? */ |
| 11874 | lua_pushfstring(L, " in function " LUA_QS, ar.name); |
| 11875 | else { |
| 11876 | if (*ar.what == 'm') /* main? */ |
| 11877 | lua_pushfstring(L, " in main chunk"); |
| 11878 | else if (*ar.what == 'C' || *ar.what == 't') |
| 11879 | lua_pushliteral(L, " ?"); /* C function or tail call */ |
| 11880 | else |
| 11881 | lua_pushfstring(L, " in function <%s:%d>", |
| 11882 | ar.short_src, ar.linedefined); |
| 11883 | } |
| 11884 | lua_concat(L, lua_gettop(L) - arg); |
| 11885 | } |
| 11886 | lua_concat(L, lua_gettop(L) - arg); |
| 11887 | return 1; |
| 11888 | } |
| 11889 | |
| 11890 | |
| 11891 | static const luaL_Reg dblib[] = { |
nothing calls this directly
no test coverage detected