diff options
| author | Mike Pall <mike> | 2012-09-19 12:06:56 +0200 |
|---|---|---|
| committer | Mike Pall <mike> | 2012-09-19 12:06:56 +0200 |
| commit | 7d49b19ad01b14d5547b888db9a31ad86f7f735f (patch) | |
| tree | bd81d28139408e9c5f1391c269d2131a41edf7d3 /src | |
| parent | 998c656dc46e03ed005bb795c3640e56c305b0a5 (diff) | |
| download | luajit-7d49b19ad01b14d5547b888db9a31ad86f7f735f.tar.gz luajit-7d49b19ad01b14d5547b888db9a31ad86f7f735f.tar.bz2 luajit-7d49b19ad01b14d5547b888db9a31ad86f7f735f.zip | |
From Lua 5.2: debug.getlocal()/setlocal() treats slot < 0 as vararg.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lj_debug.c | 26 |
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, | |||
| 189 | TValue *nextframe = size ? frame + size : NULL; | 189 | TValue *nextframe = size ? frame + size : NULL; |
| 190 | GCfunc *fn = frame_func(frame); | 190 | GCfunc *fn = frame_func(frame); |
| 191 | BCPos pc = debug_framepc(L, fn, nextframe); | 191 | BCPos pc = debug_framepc(L, fn, nextframe); |
| 192 | if (!nextframe) nextframe = L->top; | ||
| 193 | if ((int)slot1 < 0) { /* Negative slot number is for varargs. */ | ||
| 194 | if (pc != NO_BCPOS) { | ||
| 195 | GCproto *pt = funcproto(fn); | ||
| 196 | if ((pt->flags & PROTO_VARARG)) { | ||
| 197 | slot1 = pt->numparams + (BCReg)(-(int)slot1); | ||
| 198 | if (frame_isvarg(frame)) { /* Vararg frame has been set up? (pc!=0) */ | ||
| 199 | nextframe = frame; | ||
| 200 | frame = frame_prevd(frame); | ||
| 201 | } | ||
| 202 | if (frame + slot1 < nextframe) { | ||
| 203 | *name = "(*vararg)"; | ||
| 204 | return frame+slot1; | ||
| 205 | } | ||
| 206 | } | ||
| 207 | } | ||
| 208 | return NULL; | ||
| 209 | } | ||
| 192 | if (pc != NO_BCPOS && | 210 | if (pc != NO_BCPOS && |
| 193 | (*name = debug_varname(funcproto(fn), pc, slot1-1)) != NULL) | 211 | (*name = debug_varname(funcproto(fn), pc, slot1-1)) != NULL) |
| 194 | ; | 212 | ; |
| 195 | else if (slot1 > 0 && frame + slot1 < (nextframe ? nextframe : L->top)) | 213 | else if (slot1 > 0 && frame + slot1 < nextframe) |
| 196 | *name = "(*temporary)"; | 214 | *name = "(*temporary)"; |
| 197 | else | ||
| 198 | *name = NULL; | ||
| 199 | return frame+slot1; | 215 | return frame+slot1; |
| 200 | } | 216 | } |
| 201 | 217 | ||
| @@ -384,7 +400,7 @@ void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc) | |||
| 384 | 400 | ||
| 385 | 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) |
| 386 | { | 402 | { |
| 387 | const char *name; | 403 | const char *name = NULL; |
| 388 | TValue *o = debug_localname(L, ar, &name, (BCReg)n); | 404 | TValue *o = debug_localname(L, ar, &name, (BCReg)n); |
| 389 | if (name) { | 405 | if (name) { |
| 390 | copyTV(L, L->top, o); | 406 | copyTV(L, L->top, o); |
| @@ -395,7 +411,7 @@ LUA_API const char *lua_getlocal(lua_State *L, const lua_Debug *ar, int n) | |||
| 395 | 411 | ||
| 396 | LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n) | 412 | LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n) |
| 397 | { | 413 | { |
| 398 | const char *name; | 414 | const char *name = NULL; |
| 399 | TValue *o = debug_localname(L, ar, &name, (BCReg)n); | 415 | TValue *o = debug_localname(L, ar, &name, (BCReg)n); |
| 400 | if (name) | 416 | if (name) |
| 401 | copyTV(L, o, L->top-1); | 417 | copyTV(L, o, L->top-1); |
