| 108 | |
| 109 | |
| 110 | LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, |
| 111 | const char *msg, int level) { |
| 112 | lua_Debug ar; |
| 113 | int top = lua_gettop(L); |
| 114 | int numlevels = countlevels(L1); |
| 115 | int mark = (numlevels > LEVELS1 + LEVELS2) ? LEVELS1 : 0; |
| 116 | if (msg) lua_pushfstring(L, "%s\n", msg); |
| 117 | lua_pushliteral(L, "stack traceback:"); |
| 118 | while (lua_getstack(L1, level++, &ar)) { |
| 119 | if (level == mark) { /* too many levels? */ |
| 120 | lua_pushliteral(L, "\n\t..."); /* add a '...' */ |
| 121 | level = numlevels - LEVELS2; /* and skip to last ones */ |
| 122 | } |
| 123 | else { |
| 124 | lua_getinfo(L1, "Slnt", &ar); |
| 125 | lua_pushfstring(L, "\n\t%s:", ar.short_src); |
| 126 | if (ar.currentline > 0) |
| 127 | lua_pushfstring(L, "%d:", ar.currentline); |
| 128 | lua_pushliteral(L, " in "); |
| 129 | pushfuncname(L, &ar); |
| 130 | if (ar.istailcall) |
| 131 | lua_pushliteral(L, "\n\t(...tail calls...)"); |
| 132 | lua_concat(L, lua_gettop(L) - top); |
| 133 | } |
| 134 | } |
| 135 | lua_concat(L, lua_gettop(L) - top); |
| 136 | } |
| 137 | |
| 138 | /* }====================================================== */ |
| 139 |
no test coverage detected