'getlocal' gets information about parameters of Lua functions

This commit is contained in:
Roberto Ierusalimschy
2010-06-21 13:30:12 -03:00
parent bef5980744
commit ca3865cf1b
3 changed files with 37 additions and 20 deletions

View File

@@ -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;