diff options
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldblib.c,v 1.57 2002/06/13 13:44:50 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.58 2002/06/18 15:17:58 roberto Exp roberto $ |
3 | ** Interface from Lua to its debug API | 3 | ** Interface from Lua to its debug API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -184,26 +184,30 @@ static int debug (lua_State *L) { | |||
184 | static int errorfb (lua_State *L) { | 184 | static int errorfb (lua_State *L) { |
185 | int level = 1; /* skip level 0 (it's this function) */ | 185 | int level = 1; /* skip level 0 (it's this function) */ |
186 | int firstpart = 1; /* still before eventual `...' */ | 186 | int firstpart = 1; /* still before eventual `...' */ |
187 | int alllevels = 1; | ||
188 | const char *msg = lua_tostring(L, 1); | ||
187 | lua_Debug ar; | 189 | lua_Debug ar; |
188 | lua_settop(L, 0); | 190 | lua_settop(L, 0); |
189 | lua_pushliteral(L, "stack traceback:\n"); | 191 | if (msg) { |
192 | alllevels = 0; | ||
193 | if (!strstr(msg, "stack traceback:\n")) | ||
194 | lua_pushliteral(L, "stack traceback:\n"); | ||
195 | } | ||
190 | while (lua_getstack(L, level++, &ar)) { | 196 | while (lua_getstack(L, level++, &ar)) { |
191 | char buff[10]; | ||
192 | if (level > LEVELS1 && firstpart) { | 197 | if (level > LEVELS1 && firstpart) { |
193 | /* no more than `LEVELS2' more levels? */ | 198 | /* no more than `LEVELS2' more levels? */ |
194 | if (!lua_getstack(L, level+LEVELS2, &ar)) | 199 | if (!lua_getstack(L, level+LEVELS2, &ar)) |
195 | level--; /* keep going */ | 200 | level--; /* keep going */ |
196 | else { | 201 | else { |
197 | lua_pushliteral(L, " ...\n"); /* too many levels */ | 202 | lua_pushliteral(L, "\t...\n"); /* too many levels */ |
198 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ | 203 | while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ |
199 | level++; | 204 | level++; |
200 | } | 205 | } |
201 | firstpart = 0; | 206 | firstpart = 0; |
202 | continue; | 207 | continue; |
203 | } | 208 | } |
204 | sprintf(buff, "%4d- ", level-1); | 209 | lua_pushliteral(L, "\t"); |
205 | lua_pushstring(L, buff); | 210 | lua_getinfo(L, "Snlc", &ar); |
206 | lua_getinfo(L, "Snl", &ar); | ||
207 | lua_pushfstring(L, "%s:", ar.short_src); | 211 | lua_pushfstring(L, "%s:", ar.short_src); |
208 | if (ar.currentline > 0) | 212 | if (ar.currentline > 0) |
209 | lua_pushfstring(L, "%d:", ar.currentline); | 213 | lua_pushfstring(L, "%d:", ar.currentline); |
@@ -226,6 +230,7 @@ static int errorfb (lua_State *L) { | |||
226 | } | 230 | } |
227 | lua_pushliteral(L, "\n"); | 231 | lua_pushliteral(L, "\n"); |
228 | lua_concat(L, lua_gettop(L)); | 232 | lua_concat(L, lua_gettop(L)); |
233 | if (!alllevels && ar.isprotected) break; | ||
229 | } | 234 | } |
230 | lua_concat(L, lua_gettop(L)); | 235 | lua_concat(L, lua_gettop(L)); |
231 | return 1; | 236 | return 1; |