diff --git a/ldblib.c b/ldblib.c index 3a3327d5..6ca713ce 100644 --- a/ldblib.c +++ b/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.57 2002/06/13 13:44:50 roberto Exp roberto $ +** $Id: ldblib.c,v 1.58 2002/06/18 15:17:58 roberto Exp roberto $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -184,26 +184,30 @@ static int debug (lua_State *L) { static int errorfb (lua_State *L) { int level = 1; /* skip level 0 (it's this function) */ int firstpart = 1; /* still before eventual `...' */ + int alllevels = 1; + const char *msg = lua_tostring(L, 1); lua_Debug ar; lua_settop(L, 0); - lua_pushliteral(L, "stack traceback:\n"); + if (msg) { + alllevels = 0; + if (!strstr(msg, "stack traceback:\n")) + lua_pushliteral(L, "stack traceback:\n"); + } while (lua_getstack(L, level++, &ar)) { - char buff[10]; if (level > LEVELS1 && firstpart) { /* no more than `LEVELS2' more levels? */ if (!lua_getstack(L, level+LEVELS2, &ar)) level--; /* keep going */ else { - lua_pushliteral(L, " ...\n"); /* too many levels */ + lua_pushliteral(L, "\t...\n"); /* too many levels */ while (lua_getstack(L, level+LEVELS2, &ar)) /* find last levels */ level++; } firstpart = 0; continue; } - sprintf(buff, "%4d- ", level-1); - lua_pushstring(L, buff); - lua_getinfo(L, "Snl", &ar); + lua_pushliteral(L, "\t"); + lua_getinfo(L, "Snlc", &ar); lua_pushfstring(L, "%s:", ar.short_src); if (ar.currentline > 0) lua_pushfstring(L, "%d:", ar.currentline); @@ -226,6 +230,7 @@ static int errorfb (lua_State *L) { } lua_pushliteral(L, "\n"); lua_concat(L, lua_gettop(L)); + if (!alllevels && ar.isprotected) break; } lua_concat(L, lua_gettop(L)); return 1; diff --git a/ldebug.c b/ldebug.c index cd8d481d..12b85bd1 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 1.119 2002/06/13 13:39:55 roberto Exp roberto $ +** $Id: ldebug.c,v 1.120 2002/06/18 15:19:27 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -181,6 +181,7 @@ static void getname (lua_State *L, const TObject *f, lua_Debug *ar) { } + LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { StkId f; CallInfo *ci; @@ -220,6 +221,10 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) { status = 2; break; } + case 'c': { + ar->isprotected = (ci && luaD_isprotected(L, ci)); + break; + } default: status = 0; /* invalid option */ } } diff --git a/ldo.c b/ldo.c index c47fdac2..e9bd41ae 100644 --- a/ldo.c +++ b/ldo.c @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.179 2002/06/03 20:12:50 roberto Exp roberto $ +** $Id: ldo.c,v 1.180 2002/06/18 15:19:27 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -501,5 +501,13 @@ int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud) { return lj.status; } + +int luaD_isprotected (lua_State *L, CallInfo *ci) { + struct lua_longjmp *l; + for (l = L->errorJmp; l; l = l->previous) + if (l->ci+1 == ci) return 1; + return 0; +} + /* }====================================================== */ diff --git a/ldo.h b/ldo.h index 4ff39092..dc856bf6 100644 --- a/ldo.h +++ b/ldo.h @@ -1,5 +1,5 @@ /* -** $Id: ldo.h,v 1.45 2002/05/15 18:57:44 roberto Exp roberto $ +** $Id: ldo.h,v 1.46 2002/06/18 15:19:27 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -43,6 +43,7 @@ void luaD_growstack (lua_State *L, int n); void luaD_throw (lua_State *L, int errcode); int luaD_runprotected (lua_State *L, Pfunc f, TObject *ud); +int luaD_isprotected (lua_State *L, CallInfo *ci); #endif diff --git a/luadebug.h b/luadebug.h index 0836ba4a..c7ea3da4 100644 --- a/luadebug.h +++ b/luadebug.h @@ -1,5 +1,5 @@ /* -** $Id: luadebug.h,v 1.26 2002/03/14 16:50:06 roberto Exp roberto $ +** $Id: luadebug.h,v 1.27 2002/04/04 17:21:31 roberto Exp roberto $ ** Debugging API ** See Copyright Notice in lua.h */ @@ -28,14 +28,15 @@ LUA_API lua_Hook lua_setlinehook (lua_State *L, lua_Hook func); #define LUA_IDSIZE 60 struct lua_Debug { - const char *event; /* `call', `return', `line' */ - const char *name; /* (n) */ - const char *namewhat; /* (n) `global', `local', `field', `method' */ - const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ - const char *source; /* (S) */ - int currentline; /* (l) */ - int nups; /* (u) number of upvalues */ - int linedefined; /* (S) */ + const char *event; /* `call', `return', `line' */ + const char *name; /* (n) */ + const char *namewhat; /* (n) `global', `local', `field', `method' */ + const char *what; /* (S) `Lua' function, `C' function, Lua `main' */ + const char *source; /* (S) */ + int currentline; /* (l) */ + int isprotected; /* (c) function was called in protected mode */ + int nups; /* (u) number of upvalues */ + int linedefined; /* (S) */ char short_src[LUA_IDSIZE]; /* (S) */ /* private part */ int i_ci; /* active function */