diff options
-rw-r--r-- | ldebug.c | 38 | ||||
-rw-r--r-- | ldo.c | 14 | ||||
-rw-r--r-- | ldo.h | 4 | ||||
-rw-r--r-- | liolib.c | 7 | ||||
-rw-r--r-- | lobject.c | 4 | ||||
-rw-r--r-- | lvm.c | 4 |
6 files changed, 41 insertions, 30 deletions
@@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 1.2 1999/12/23 18:19:57 roberto Exp roberto $ +** $Id: ldebug.c,v 1.3 1999/12/29 16:31:15 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -45,9 +45,9 @@ int lua_setdebug (lua_State *L, int debug) { } -lua_Function lua_stackedfunction (lua_State *L, int level) { +static lua_Function aux_stackedfunction (lua_State *L, int level, StkId top) { int i; - for (i = (L->top-1)-L->stack; i>=0; i--) { + for (i = (top-1)-L->stack; i>=0; i--) { if (is_T_MARK(L->stack[i].ttype)) { if (level == 0) return L->stack+i; @@ -58,10 +58,15 @@ lua_Function lua_stackedfunction (lua_State *L, int level) { } -const char *luaG_getname (lua_State *L, const char **name) { - lua_Function f = lua_stackedfunction(L, 0); +lua_Function lua_stackedfunction (lua_State *L, int level) { + return aux_stackedfunction(L, level, L->top); +} + + +static const char *luaG_getname (lua_State *L, const char **name, StkId top) { + lua_Function f = aux_stackedfunction(L, 0, top); if (f == LUA_NOOBJECT || !hasdebuginfo(L, f) || ttype(f+2) == LUA_T_NIL) - return NULL; /* no name available */ + return ""; /* no name available */ else { int i = (f+2)->value.i; if (ttype(f) == LUA_T_LCLMARK) @@ -69,14 +74,7 @@ const char *luaG_getname (lua_State *L, const char **name) { LUA_ASSERT(L, ttype(f) == LUA_T_LMARK, "must be a Lua function"); LUA_ASSERT(L, ttype(&tfvalue(f)->consts[i]) == LUA_T_STRING, ""); *name = tsvalue(&tfvalue(f)->consts[i])->str; - switch (ttype(f+2)) { - case LUA_T_NGLOBAL: return "global"; - case LUA_T_NLOCAL: return "local"; - case LUA_T_NDOT: return "field"; - default: - LUA_INTERNALERROR(L, "invalid tag for NAME"); - return NULL; /* unreacheable; to avoid warnings */ - } + return luaO_typename(f+2); } } @@ -162,8 +160,14 @@ static int checkfunc (lua_State *L, TObject *o) { const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { - /* try to find a name for given function */ GlobalVar *g; + if (is_T_MARK(ttype(o))) { /* `o' is an active function? */ + /* look for caller debug information */ + const char *kind = luaG_getname(L, name, o); + if (*kind) return kind; + /* else go through */ + } + /* try to find a name for given function */ luaA_setnormalized(L->top, o); /* to be used by `checkfunc' */ for (g=L->rootglobal; g; g=g->next) { if (checkfunc(L, &g->value)) { @@ -180,8 +184,8 @@ const char *lua_getobjname (lua_State *L, lua_Object o, const char **name) { static void call_index_error (lua_State *L, TObject *o, const char *tp, const char *v) { const char *name; - const char *kind = luaG_getname(L, &name); - if (kind) { /* is there a name? */ + const char *kind = luaG_getname(L, &name, L->top); + if (*kind) { /* is there a name? */ luaL_verror(L, "%.10s `%.30s' is not a %.10s", kind, name, tp); } else { @@ -1,5 +1,5 @@ /* -** $Id: ldo.c,v 1.61 1999/12/27 17:33:22 roberto Exp roberto $ +** $Id: ldo.c,v 1.62 1999/12/29 16:31:15 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -114,8 +114,8 @@ void luaD_lineHook (lua_State *L, int line) { } -static void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook, - int isreturn) { +void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook, + int isreturn) { if (L->allowhooks) { struct C_Lua_Stack oldCLS = L->Cstack; StkId old_top = L->Cstack.lua2C = L->Cstack.base = L->top; @@ -156,6 +156,8 @@ static StkId callC (lua_State *L, lua_CFunction f, StkId base) { L->Cstack.num = numarg; L->Cstack.lua2C = base; L->Cstack.base = L->top; + if (L->callhook) + luaD_callHook(L, base-1, L->callhook, 0); (*f)(L); /* do the actual call */ firstResult = L->Cstack.base; L->Cstack = oldCLS; @@ -194,8 +196,6 @@ void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults) { void luaD_call (lua_State *L, StkId func, int nResults) { StkId firstResult; lua_CHFunction callhook = L->callhook; - if (callhook) - luaD_callHook(L, func, callhook, 0); retry: /* for `function' tag method */ switch (ttype(func)) { case LUA_T_CPROTO: @@ -224,10 +224,10 @@ void luaD_call (lua_State *L, StkId func, int nResults) { luaG_callerror(L, func); luaD_openstack(L, func); *func = *im; /* tag method is the new function to be called */ - goto retry; /* retry the call (without calling callhook again) */ + goto retry; /* retry the call */ } } - if (callhook) /* same hook that was used at entry */ + if (callhook) /* same hook that was active at entry */ luaD_callHook(L, NULL, callhook, 1); /* `return' hook */ /* adjust the number of results */ if (nResults == MULT_RET) @@ -1,5 +1,5 @@ /* -** $Id: ldo.h,v 1.14 1999/12/06 11:41:28 roberto Exp roberto $ +** $Id: ldo.h,v 1.15 1999/12/21 18:04:41 roberto Exp roberto $ ** Stack and Call structure of Lua ** See Copyright Notice in lua.h */ @@ -26,6 +26,8 @@ void luaD_init (lua_State *L, int stacksize); void luaD_adjusttop (lua_State *L, StkId base, int extra); void luaD_openstack (lua_State *L, StkId pos); +void luaD_callHook (lua_State *L, StkId func, lua_CHFunction callhook, + int isreturn); void luaD_lineHook (lua_State *L, int line); void luaD_call (lua_State *L, StkId func, int nResults); void luaD_callTM (lua_State *L, const TObject *f, int nParams, int nResults); @@ -1,5 +1,5 @@ /* -** $Id: liolib.c,v 1.53 1999/12/27 13:04:53 roberto Exp roberto $ +** $Id: liolib.c,v 1.54 1999/12/28 11:52:49 roberto Exp roberto $ ** Standard I/O (and system) library ** See Copyright Notice in lua.h */ @@ -546,9 +546,12 @@ static void errorfb (lua_State *L) { break; /* buffer is full */ } switch (*lua_getobjname(L, func, &name)) { - case 'g': + case 'g': case 'l': sprintf(buff+strlen(buff), "function `%.50s'", name); break; + case 'f': + sprintf(buff+strlen(buff), "method `%.50s'", name); + break; case 't': sprintf(buff+strlen(buff), "`%.50s' tag method", name); break; @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 1.27 1999/12/14 18:31:20 roberto Exp roberto $ +** $Id: lobject.c,v 1.28 1999/12/23 18:19:57 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -16,7 +16,7 @@ const char *const luaO_typenames[] = { /* ORDER LUA_T */ "userdata", "number", "string", "table", "function", "function", "nil", "function", "function", "function", "function", "function", "function", - "line", NULL + "line", "global", "local", "field", NULL }; @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.76 1999/12/27 17:33:22 roberto Exp roberto $ +** $Id: lvm.c,v 1.77 1999/12/29 16:31:15 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -297,6 +297,8 @@ StkId luaV_execute (lua_State *L, const Closure *cl, const TProtoFunc *tf, register StkId top; /* keep top local, for performance */ register const Byte *pc = tf->code; const TObject *consts = tf->consts; + if (L->callhook) + luaD_callHook(L, base-1, L->callhook, 0); luaD_checkstack(L, (*pc++)+EXTRA_STACK); if (*pc < ZEROVARARG) luaD_adjusttop(L, base, *(pc++)); |