diff options
author | Mike Pall <mike> | 2012-09-20 15:19:48 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2012-09-20 15:19:48 +0200 |
commit | 965694b0afdebfa8b4b9b28a6a7f9341ea2f14f0 (patch) | |
tree | 7c1a4fdce3ad9851e112703620da8b9e6eb295b6 | |
parent | 2d3c1967c7e42c343bd3cb6798d7b7ffe89a5831 (diff) | |
download | luajit-965694b0afdebfa8b4b9b28a6a7f9341ea2f14f0.tar.gz luajit-965694b0afdebfa8b4b9b28a6a7f9341ea2f14f0.tar.bz2 luajit-965694b0afdebfa8b4b9b28a6a7f9341ea2f14f0.zip |
Fix 'f' and 'L' options for debug.getinfo() and lua_getinfo().
-rw-r--r-- | src/lib_debug.c | 49 | ||||
-rw-r--r-- | src/lj_debug.c | 54 |
2 files changed, 58 insertions, 45 deletions
diff --git a/src/lib_debug.c b/src/lib_debug.c index 1487f12b..ab504de7 100644 --- a/src/lib_debug.c +++ b/src/lib_debug.c | |||
@@ -102,7 +102,7 @@ static void treatstackoption(lua_State *L, lua_State *L1, const char *fname) | |||
102 | LJLIB_CF(debug_getinfo) | 102 | LJLIB_CF(debug_getinfo) |
103 | { | 103 | { |
104 | lua_Debug ar; | 104 | lua_Debug ar; |
105 | int arg; | 105 | int arg, opt_f = 0, opt_L = 0; |
106 | lua_State *L1 = getthread(L, &arg); | 106 | lua_State *L1 = getthread(L, &arg); |
107 | const char *options = luaL_optstring(L, arg+2, "flnSu"); | 107 | const char *options = luaL_optstring(L, arg+2, "flnSu"); |
108 | if (lua_isnumber(L, arg+1)) { | 108 | if (lua_isnumber(L, arg+1)) { |
@@ -118,27 +118,34 @@ LJLIB_CF(debug_getinfo) | |||
118 | } | 118 | } |
119 | if (!lua_getinfo(L1, options, &ar)) | 119 | if (!lua_getinfo(L1, options, &ar)) |
120 | lj_err_arg(L, arg+2, LJ_ERR_INVOPT); | 120 | lj_err_arg(L, arg+2, LJ_ERR_INVOPT); |
121 | lua_createtable(L, 0, 16); | 121 | lua_createtable(L, 0, 16); /* Create result table. */ |
122 | if (strchr(options, 'S')) { | 122 | for (; *options; options++) { |
123 | settabss(L, "source", ar.source); | 123 | switch (*options) { |
124 | settabss(L, "short_src", ar.short_src); | 124 | case 'S': |
125 | settabsi(L, "linedefined", ar.linedefined); | 125 | settabss(L, "source", ar.source); |
126 | settabsi(L, "lastlinedefined", ar.lastlinedefined); | 126 | settabss(L, "short_src", ar.short_src); |
127 | settabss(L, "what", ar.what); | 127 | settabsi(L, "linedefined", ar.linedefined); |
128 | } | 128 | settabsi(L, "lastlinedefined", ar.lastlinedefined); |
129 | if (strchr(options, 'l')) | 129 | settabss(L, "what", ar.what); |
130 | settabsi(L, "currentline", ar.currentline); | 130 | break; |
131 | if (strchr(options, 'u')) | 131 | case 'l': |
132 | settabsi(L, "nups", ar.nups); | 132 | settabsi(L, "currentline", ar.currentline); |
133 | if (strchr(options, 'n')) { | 133 | break; |
134 | settabss(L, "name", ar.name); | 134 | case 'u': |
135 | settabss(L, "namewhat", ar.namewhat); | 135 | settabsi(L, "nups", ar.nups); |
136 | break; | ||
137 | case 'n': | ||
138 | settabss(L, "name", ar.name); | ||
139 | settabss(L, "namewhat", ar.namewhat); | ||
140 | break; | ||
141 | case 'f': opt_f = 1; break; | ||
142 | case 'L': opt_L = 1; break; | ||
143 | default: break; | ||
144 | } | ||
136 | } | 145 | } |
137 | if (strchr(options, 'L')) | 146 | if (opt_L) treatstackoption(L, L1, "activelines"); |
138 | treatstackoption(L, L1, "activelines"); | 147 | if (opt_f) treatstackoption(L, L1, "func"); |
139 | if (strchr(options, 'f')) | 148 | return 1; /* Return result table. */ |
140 | treatstackoption(L, L1, "func"); | ||
141 | return 1; /* return table */ | ||
142 | } | 149 | } |
143 | 150 | ||
144 | LJLIB_CF(debug_getlocal) | 151 | LJLIB_CF(debug_getlocal) |
diff --git a/src/lj_debug.c b/src/lj_debug.c index d5693779..7dba8072 100644 --- a/src/lj_debug.c +++ b/src/lj_debug.c | |||
@@ -425,7 +425,7 @@ LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n) | |||
425 | 425 | ||
426 | LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) | 426 | LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) |
427 | { | 427 | { |
428 | int status = 1; | 428 | int opt_f = 0, opt_L = 0; |
429 | TValue *frame = NULL; | 429 | TValue *frame = NULL; |
430 | TValue *nextframe = NULL; | 430 | TValue *nextframe = NULL; |
431 | GCfunc *fn; | 431 | GCfunc *fn; |
@@ -478,35 +478,41 @@ LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) | |||
478 | ar->name = NULL; | 478 | ar->name = NULL; |
479 | } | 479 | } |
480 | } else if (*what == 'f') { | 480 | } else if (*what == 'f') { |
481 | setfuncV(L, L->top, fn); | 481 | opt_f = 1; |
482 | incr_top(L); | ||
483 | } else if (*what == 'L') { | 482 | } else if (*what == 'L') { |
484 | if (isluafunc(fn)) { | 483 | opt_L = 1; |
485 | GCtab *t = lj_tab_new(L, 0, 0); | 484 | } else { |
486 | GCproto *pt = funcproto(fn); | 485 | return 0; /* Bad option. */ |
487 | const void *lineinfo = proto_lineinfo(pt); | 486 | } |
488 | if (lineinfo) { | 487 | } |
489 | BCLine first = pt->firstline; | 488 | if (opt_f) { |
490 | int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4; | 489 | setfuncV(L, L->top, fn); |
491 | MSize i, szl = pt->sizebc-1; | 490 | incr_top(L); |
492 | for (i = 0; i < szl; i++) { | 491 | } |
493 | BCLine line = first + | 492 | if (opt_L) { |
494 | (sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] : | 493 | if (isluafunc(fn)) { |
495 | sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] : | 494 | GCtab *t = lj_tab_new(L, 0, 0); |
496 | (BCLine)((const uint32_t *)lineinfo)[i]); | 495 | GCproto *pt = funcproto(fn); |
497 | setboolV(lj_tab_setint(L, t, line), 1); | 496 | const void *lineinfo = proto_lineinfo(pt); |
498 | } | 497 | if (lineinfo) { |
498 | BCLine first = pt->firstline; | ||
499 | int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4; | ||
500 | MSize i, szl = pt->sizebc-1; | ||
501 | for (i = 0; i < szl; i++) { | ||
502 | BCLine line = first + | ||
503 | (sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] : | ||
504 | sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] : | ||
505 | (BCLine)((const uint32_t *)lineinfo)[i]); | ||
506 | setboolV(lj_tab_setint(L, t, line), 1); | ||
499 | } | 507 | } |
500 | settabV(L, L->top, t); | ||
501 | } else { | ||
502 | setnilV(L->top); | ||
503 | } | 508 | } |
504 | incr_top(L); | 509 | settabV(L, L->top, t); |
505 | } else { | 510 | } else { |
506 | status = 0; /* Bad option. */ | 511 | setnilV(L->top); |
507 | } | 512 | } |
513 | incr_top(L); | ||
508 | } | 514 | } |
509 | return status; | 515 | return 1; /* Ok. */ |
510 | } | 516 | } |
511 | 517 | ||
512 | LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar) | 518 | LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar) |