mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
From Lua 5.2: debug.getlocal() accepts function arg, too.
This commit is contained in:
parent
7d49b19ad0
commit
c687d01c46
@ -145,9 +145,15 @@ LJLIB_CF(debug_getlocal)
|
||||
lua_State *L1 = getthread(L, &arg);
|
||||
lua_Debug ar;
|
||||
const char *name;
|
||||
int slot = lj_lib_checkint(L, arg+2);
|
||||
if (tvisfunc(L->base+arg)) {
|
||||
L->top = L->base+arg+1;
|
||||
lua_pushstring(L, lua_getlocal(L, NULL, slot));
|
||||
return 1;
|
||||
}
|
||||
if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar))
|
||||
lj_err_arg(L, arg+1, LJ_ERR_LVLRNG);
|
||||
name = lua_getlocal(L1, &ar, lj_lib_checkint(L, arg+2));
|
||||
name = lua_getlocal(L1, &ar, slot);
|
||||
if (name) {
|
||||
lua_xmove(L1, L, 1);
|
||||
lua_pushstring(L, name);
|
||||
|
@ -401,11 +401,15 @@ void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc)
|
||||
LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n)
|
||||
{
|
||||
const char *name = NULL;
|
||||
if (ar) {
|
||||
TValue *o = debug_localname(L, ar, &name, (BCReg)n);
|
||||
if (name) {
|
||||
copyTV(L, L->top, o);
|
||||
incr_top(L);
|
||||
}
|
||||
} else if (tvisfunc(L->top-1) && isluafunc(funcV(L->top-1))) {
|
||||
name = debug_varname(funcproto(funcV(L->top-1)), 0, (BCReg)n-1);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user