| 129 | |
| 130 | |
| 131 | LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, |
| 132 | const char *msg, int level) { |
| 133 | luaL_Buffer b; |
| 134 | lua_Debug ar; |
| 135 | int last = lastlevel(L1); |
| 136 | int limit2show = (last - level > LEVELS1 + LEVELS2) ? LEVELS1 : -1; |
| 137 | luaL_buffinit(L, &b); |
| 138 | if (msg) { |
| 139 | luaL_addstring(&b, msg); |
| 140 | luaL_addchar(&b, '\n'); |
| 141 | } |
| 142 | luaL_addstring(&b, "stack traceback:"); |
| 143 | while (lua_getstack(L1, level++, &ar)) { |
| 144 | if (limit2show-- == 0) { /* too many levels? */ |
| 145 | int n = last - level - LEVELS2 + 1; /* number of levels to skip */ |
| 146 | lua_pushfstring(L, "\n\t...\t(skipping %d levels)", n); |
| 147 | luaL_addvalue(&b); /* add warning about skip */ |
| 148 | level += n; /* and skip to last levels */ |
| 149 | } |
| 150 | else { |
| 151 | lua_getinfo(L1, "Slnt", &ar); |
| 152 | if (ar.currentline <= 0) |
| 153 | lua_pushfstring(L, "\n\t%s: in ", ar.short_src); |
| 154 | else |
| 155 | lua_pushfstring(L, "\n\t%s:%d: in ", ar.short_src, ar.currentline); |
| 156 | luaL_addvalue(&b); |
| 157 | pushfuncname(L, &ar); |
| 158 | luaL_addvalue(&b); |
| 159 | if (ar.istailcall) |
| 160 | luaL_addstring(&b, "\n\t(...tail calls...)"); |
| 161 | } |
| 162 | } |
| 163 | luaL_pushresult(&b); |
| 164 | } |
| 165 | |
| 166 | /* }====================================================== */ |
| 167 |
no test coverage detected