| 123 | |
| 124 | |
| 125 | LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, |
| 126 | const char *msg, int level) { |
| 127 | lua_Debug ar; |
| 128 | int top = lua_gettop(L); |
| 129 | int last = lastlevel(L1); |
| 130 | int n1 = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1; |
| 131 | if (msg) |
| 132 | lua_pushfstring(L, "%s\n", msg); |
| 133 | luaL_checkstack(L, 10, NULL); |
| 134 | lua_pushliteral(L, "stack traceback:"); |
| 135 | while (lua_getstack(L1, level++, &ar)) { |
| 136 | if (n1-- == 0) { /* too many levels? */ |
| 137 | lua_pushliteral(L, "\n\t..."); /* add a '...' */ |
| 138 | level = last - LEVELS2 + 1; /* and skip to last ones */ |
| 139 | } |
| 140 | else { |
| 141 | lua_getinfo(L1, "Slnt", &ar); |
| 142 | lua_pushfstring(L, "\n\t%s:", ar.short_src); |
| 143 | if (ar.currentline > 0) |
| 144 | lua_pushfstring(L, "%d:", ar.currentline); |
| 145 | lua_pushliteral(L, " in "); |
| 146 | pushfuncname(L, &ar); |
| 147 | if (ar.istailcall) |
| 148 | lua_pushliteral(L, "\n\t(...tail calls...)"); |
| 149 | lua_concat(L, lua_gettop(L) - top); |
| 150 | } |
| 151 | } |
| 152 | lua_concat(L, lua_gettop(L) - top); |
| 153 | } |
| 154 | |
| 155 | /* }====================================================== */ |
| 156 |
no test coverage detected