lua_getlocal/setlocal work also for C locals and temporaries
This commit is contained in:
51
ldebug.c
51
ldebug.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ldebug.c,v 2.26 2005/08/04 13:37:38 roberto Exp roberto $
|
** $Id: ldebug.c,v 2.27 2005/10/06 20:43:44 roberto Exp roberto $
|
||||||
** Debug Interface
|
** Debug Interface
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -109,40 +109,39 @@ static Proto *getluaproto (CallInfo *ci) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
|
static const char *findlocal (lua_State *L, CallInfo *ci, int n) {
|
||||||
const char *name;
|
const char *name;
|
||||||
CallInfo *ci;
|
Proto *fp = getluaproto(ci);
|
||||||
Proto *fp;
|
if (fp && (name = luaF_getlocalname(fp, n, currentpc(L, ci))) != NULL)
|
||||||
lua_lock(L);
|
return name; /* is a local variable in a Lua function */
|
||||||
name = NULL;
|
else {
|
||||||
ci = L->base_ci + ar->i_ci;
|
StkId limit = (ci == L->ci) ? L->top : (ci+1)->func;
|
||||||
fp = getluaproto(ci);
|
if (limit - ci->base >= n && n > 0) /* is 'n' inside 'ci' stack? */
|
||||||
if (fp) { /* is a Lua function? */
|
return "(*temporary)";
|
||||||
name = luaF_getlocalname(fp, n, currentpc(L, ci));
|
else
|
||||||
if (name)
|
return NULL;
|
||||||
luaA_pushobject(L, ci->base+(n-1)); /* push value */
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
|
||||||
|
CallInfo *ci = L->base_ci + ar->i_ci;
|
||||||
|
const char *name = findlocal(L, ci, n);
|
||||||
|
lua_lock(L);
|
||||||
|
if (name)
|
||||||
|
luaA_pushobject(L, ci->base + (n - 1));
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
|
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
|
||||||
const char *name;
|
CallInfo *ci = L->base_ci + ar->i_ci;
|
||||||
CallInfo *ci;
|
const char *name = findlocal(L, ci, n);
|
||||||
Proto *fp;
|
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
name = NULL;
|
if (name)
|
||||||
ci = L->base_ci + ar->i_ci;
|
setobjs2s(L, ci->base + (n - 1), L->top - 1);
|
||||||
fp = getluaproto(ci);
|
L->top--; /* pop value */
|
||||||
L->top--; /* pop new value */
|
|
||||||
if (fp) { /* is a Lua function? */
|
|
||||||
name = luaF_getlocalname(fp, n, currentpc(L, ci));
|
|
||||||
if (!name || name[0] == '(') /* `(' starts private locals */
|
|
||||||
name = NULL;
|
|
||||||
else
|
|
||||||
setobjs2s(L, ci->base+(n-1), L->top);
|
|
||||||
}
|
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user