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