diff options
Diffstat (limited to 'ldblib.c')
| -rw-r--r-- | ldblib.c | 21 |
1 files changed, 8 insertions, 13 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldblib.c,v 1.63 2002/07/08 20:22:08 roberto Exp roberto $ | 2 | ** $Id: ldblib.c,v 1.64 2002/07/17 16:25:13 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 | */ |
| @@ -194,15 +194,11 @@ static int debug (lua_State *L) { | |||
| 194 | static int errorfb (lua_State *L) { | 194 | static int errorfb (lua_State *L) { |
| 195 | int level = 1; /* skip level 0 (it's this function) */ | 195 | int level = 1; /* skip level 0 (it's this function) */ |
| 196 | int firstpart = 1; /* still before eventual `...' */ | 196 | int firstpart = 1; /* still before eventual `...' */ |
| 197 | int alllevels = 1; | ||
| 198 | const char *msg = lua_tostring(L, 1); | ||
| 199 | lua_Debug ar; | 197 | lua_Debug ar; |
| 200 | lua_settop(L, 0); | 198 | if (lua_gettop(L) == 0) |
| 201 | if (msg) { | 199 | lua_pushliteral(L, ""); |
| 202 | alllevels = 0; | 200 | else if (!lua_isstring(L, 1)) return 1; /* no string message */ |
| 203 | if (!strstr(msg, "stack traceback:\n")) | 201 | lua_pushliteral(L, "stack traceback:\n"); |
| 204 | lua_pushliteral(L, "stack traceback:\n"); | ||
| 205 | } | ||
| 206 | while (lua_getstack(L, level++, &ar)) { | 202 | while (lua_getstack(L, level++, &ar)) { |
| 207 | if (level > LEVELS1 && firstpart) { | 203 | if (level > LEVELS1 && firstpart) { |
| 208 | /* no more than `LEVELS2' more levels? */ | 204 | /* no more than `LEVELS2' more levels? */ |
| @@ -217,7 +213,7 @@ static int errorfb (lua_State *L) { | |||
| 217 | continue; | 213 | continue; |
| 218 | } | 214 | } |
| 219 | lua_pushliteral(L, "\t"); | 215 | lua_pushliteral(L, "\t"); |
| 220 | lua_getinfo(L, "Snlc", &ar); | 216 | lua_getinfo(L, "Snl", &ar); |
| 221 | lua_pushfstring(L, "%s:", ar.short_src); | 217 | lua_pushfstring(L, "%s:", ar.short_src); |
| 222 | if (ar.currentline > 0) | 218 | if (ar.currentline > 0) |
| 223 | lua_pushfstring(L, "%d:", ar.currentline); | 219 | lua_pushfstring(L, "%d:", ar.currentline); |
| @@ -240,7 +236,6 @@ static int errorfb (lua_State *L) { | |||
| 240 | } | 236 | } |
| 241 | lua_pushliteral(L, "\n"); | 237 | lua_pushliteral(L, "\n"); |
| 242 | lua_concat(L, lua_gettop(L)); | 238 | lua_concat(L, lua_gettop(L)); |
| 243 | if (!alllevels && ar.isprotected) break; | ||
| 244 | } | 239 | } |
| 245 | lua_concat(L, lua_gettop(L)); | 240 | lua_concat(L, lua_gettop(L)); |
| 246 | return 1; | 241 | return 1; |
| @@ -261,9 +256,9 @@ static const luaL_reg dblib[] = { | |||
| 261 | 256 | ||
| 262 | LUALIB_API int lua_dblibopen (lua_State *L) { | 257 | LUALIB_API int lua_dblibopen (lua_State *L) { |
| 263 | luaL_opennamedlib(L, LUA_DBLIBNAME, dblib, 0); | 258 | luaL_opennamedlib(L, LUA_DBLIBNAME, dblib, 0); |
| 264 | lua_pushliteral(L, LUA_TRACEBACK); | 259 | lua_pushliteral(L, "_TRACEBACK"); |
| 265 | lua_pushcfunction(L, errorfb); | 260 | lua_pushcfunction(L, errorfb); |
| 266 | lua_settable(L, LUA_REGISTRYINDEX); | 261 | lua_settable(L, LUA_GLOBALSINDEX); |
| 267 | return 0; | 262 | return 0; |
| 268 | } | 263 | } |
| 269 | 264 | ||
