From Lua 5.2: debug.getlocal() accepts function arg, too.

This commit is contained in:
Mike Pall 2012-09-19 12:08:35 +02:00
parent 7d49b19ad0
commit c687d01c46
2 changed files with 15 additions and 5 deletions

View File

@ -145,9 +145,15 @@ LJLIB_CF(debug_getlocal)
lua_State *L1 = getthread(L, &arg); lua_State *L1 = getthread(L, &arg);
lua_Debug ar; lua_Debug ar;
const char *name; 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)) if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar))
lj_err_arg(L, arg+1, LJ_ERR_LVLRNG); 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) { if (name) {
lua_xmove(L1, L, 1); lua_xmove(L1, L, 1);
lua_pushstring(L, name); lua_pushstring(L, name);

View File

@ -401,10 +401,14 @@ 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) LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n)
{ {
const char *name = NULL; const char *name = NULL;
TValue *o = debug_localname(L, ar, &name, (BCReg)n); if (ar) {
if (name) { TValue *o = debug_localname(L, ar, &name, (BCReg)n);
copyTV(L, L->top, o); if (name) {
incr_top(L); 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; return name;
} }