summaryrefslogtreecommitdiff
path: root/src/lj_debug.c
diff options
context:
space:
mode:
authorMike Pall <mike>2012-09-19 12:06:56 +0200
committerMike Pall <mike>2012-09-19 12:06:56 +0200
commit7d49b19ad01b14d5547b888db9a31ad86f7f735f (patch)
treebd81d28139408e9c5f1391c269d2131a41edf7d3 /src/lj_debug.c
parent998c656dc46e03ed005bb795c3640e56c305b0a5 (diff)
downloadluajit2-7d49b19ad01b14d5547b888db9a31ad86f7f735f.tar.gz
From Lua 5.2: debug.getlocal()/setlocal() treats slot < 0 as vararg.
Diffstat (limited to 'src/lj_debug.c')
-rw-r--r--src/lj_debug.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/lj_debug.c b/src/lj_debug.c
index c2dc0dd8..85dbac50 100644
--- a/src/lj_debug.c
+++ b/src/lj_debug.c
@@ -189,13 +189,29 @@ static TValue *debug_localname(lua_State *L, const lua_Debug *ar,
TValue *nextframe = size ? frame + size : NULL;
GCfunc *fn = frame_func(frame);
BCPos pc = debug_framepc(L, fn, nextframe);
+ if (!nextframe) nextframe = L->top;
+ if ((int)slot1 < 0) { /* Negative slot number is for varargs. */
+ if (pc != NO_BCPOS) {
+ GCproto *pt = funcproto(fn);
+ if ((pt->flags & PROTO_VARARG)) {
+ slot1 = pt->numparams + (BCReg)(-(int)slot1);
+ if (frame_isvarg(frame)) { /* Vararg frame has been set up? (pc!=0) */
+ nextframe = frame;
+ frame = frame_prevd(frame);
+ }
+ if (frame + slot1 < nextframe) {
+ *name = "(*vararg)";
+ return frame+slot1;
+ }
+ }
+ }
+ return NULL;
+ }
if (pc != NO_BCPOS &&
(*name = debug_varname(funcproto(fn), pc, slot1-1)) != NULL)
;
- else if (slot1 > 0 && frame + slot1 < (nextframe ? nextframe : L->top))
+ else if (slot1 > 0 && frame + slot1 < nextframe)
*name = "(*temporary)";
- else
- *name = NULL;
return frame+slot1;
}
@@ -384,7 +400,7 @@ 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;
+ const char *name = NULL;
TValue *o = debug_localname(L, ar, &name, (BCReg)n);
if (name) {
copyTV(L, L->top, o);
@@ -395,7 +411,7 @@ LUA_API const char *lua_getlocal(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;
+ const char *name = NULL;
TValue *o = debug_localname(L, ar, &name, (BCReg)n);
if (name)
copyTV(L, o, L->top-1);