diff options
| -rw-r--r-- | src/lib_debug.c | 8 | ||||
| -rw-r--r-- | src/lj_debug.c | 12 |
2 files changed, 15 insertions, 5 deletions
diff --git a/src/lib_debug.c b/src/lib_debug.c index 740708cf..f6818bbf 100644 --- a/src/lib_debug.c +++ b/src/lib_debug.c | |||
| @@ -145,9 +145,15 @@ LJLIB_CF(debug_getlocal) | |||
| 145 | lua_State *L1 = getthread(L, &arg); | 145 | lua_State *L1 = getthread(L, &arg); |
| 146 | lua_Debug ar; | 146 | lua_Debug ar; |
| 147 | const char *name; | 147 | const char *name; |
| 148 | int slot = lj_lib_checkint(L, arg+2); | ||
| 149 | if (tvisfunc(L->base+arg)) { | ||
| 150 | L->top = L->base+arg+1; | ||
| 151 | lua_pushstring(L, lua_getlocal(L, NULL, slot)); | ||
| 152 | return 1; | ||
| 153 | } | ||
| 148 | if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar)) | 154 | if (!lua_getstack(L1, lj_lib_checkint(L, arg+1), &ar)) |
| 149 | lj_err_arg(L, arg+1, LJ_ERR_LVLRNG); | 155 | lj_err_arg(L, arg+1, LJ_ERR_LVLRNG); |
| 150 | name = lua_getlocal(L1, &ar, lj_lib_checkint(L, arg+2)); | 156 | name = lua_getlocal(L1, &ar, slot); |
| 151 | if (name) { | 157 | if (name) { |
| 152 | lua_xmove(L1, L, 1); | 158 | lua_xmove(L1, L, 1); |
| 153 | lua_pushstring(L, name); | 159 | lua_pushstring(L, name); |
diff --git a/src/lj_debug.c b/src/lj_debug.c index 85dbac50..d5693779 100644 --- a/src/lj_debug.c +++ b/src/lj_debug.c | |||
| @@ -401,10 +401,14 @@ void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc) | |||
| 401 | LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n) | 401 | LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n) |
| 402 | { | 402 | { |
| 403 | const char *name = NULL; | 403 | const char *name = NULL; |
| 404 | TValue *o = debug_localname(L, ar, &name, (BCReg)n); | 404 | if (ar) { |
| 405 | if (name) { | 405 | TValue *o = debug_localname(L, ar, &name, (BCReg)n); |
| 406 | copyTV(L, L->top, o); | 406 | if (name) { |
| 407 | incr_top(L); | 407 | copyTV(L, L->top, o); |
| 408 | incr_top(L); | ||
| 409 | } | ||
| 410 | } else if (tvisfunc(L->top-1) && isluafunc(funcV(L->top-1))) { | ||
| 411 | name = debug_varname(funcproto(funcV(L->top-1)), 0, (BCReg)n-1); | ||
| 408 | } | 412 | } |
| 409 | return name; | 413 | return name; |
| 410 | } | 414 | } |
