From ca3865cf1b1e0195de9d1c71e48305146798cb95 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 21 Jun 2010 13:30:12 -0300 Subject: 'getlocal' gets information about parameters of Lua functions --- ldebug.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'ldebug.c') diff --git a/ldebug.c b/ldebug.c index 304e5708..fcead7ce 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 2.70 2010/04/13 20:48:12 roberto Exp roberto $ +** $Id: ldebug.c,v 2.71 2010/06/16 13:44:36 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -119,12 +119,21 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n, LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { - StkId pos; - const char *name = findlocal(L, ar->i_ci, n, &pos); + const char *name; lua_lock(L); - if (name) { - setobj2s(L, L->top, pos); - api_incr_top(L); + if (ar == NULL) { /* information about non-active function? */ + if (!isLfunction(L->top - 1)) /* not a Lua function? */ + name = NULL; + else /* consider live variables at function start (parameters) */ + name = luaF_getlocalname(clvalue(L->top - 1)->l.p, n, 0); + } + else { /* active function; get information through 'ar' */ + StkId pos; + name = findlocal(L, ar->i_ci, n, &pos); + if (name) { + setobj2s(L, L->top, pos); + api_incr_top(L); + } } lua_unlock(L); return name; -- cgit v1.2.3-55-g6feb