mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-12 17:24:09 +00:00
Fix 'f' and 'L' options for debug.getinfo() and lua_getinfo().
This commit is contained in:
parent
2d3c1967c7
commit
965694b0af
@ -102,7 +102,7 @@ static void treatstackoption(lua_State *L, lua_State *L1, const char *fname)
|
||||
LJLIB_CF(debug_getinfo)
|
||||
{
|
||||
lua_Debug ar;
|
||||
int arg;
|
||||
int arg, opt_f = 0, opt_L = 0;
|
||||
lua_State *L1 = getthread(L, &arg);
|
||||
const char *options = luaL_optstring(L, arg+2, "flnSu");
|
||||
if (lua_isnumber(L, arg+1)) {
|
||||
@ -118,27 +118,34 @@ LJLIB_CF(debug_getinfo)
|
||||
}
|
||||
if (!lua_getinfo(L1, options, &ar))
|
||||
lj_err_arg(L, arg+2, LJ_ERR_INVOPT);
|
||||
lua_createtable(L, 0, 16);
|
||||
if (strchr(options, 'S')) {
|
||||
settabss(L, "source", ar.source);
|
||||
settabss(L, "short_src", ar.short_src);
|
||||
settabsi(L, "linedefined", ar.linedefined);
|
||||
settabsi(L, "lastlinedefined", ar.lastlinedefined);
|
||||
settabss(L, "what", ar.what);
|
||||
lua_createtable(L, 0, 16); /* Create result table. */
|
||||
for (; *options; options++) {
|
||||
switch (*options) {
|
||||
case 'S':
|
||||
settabss(L, "source", ar.source);
|
||||
settabss(L, "short_src", ar.short_src);
|
||||
settabsi(L, "linedefined", ar.linedefined);
|
||||
settabsi(L, "lastlinedefined", ar.lastlinedefined);
|
||||
settabss(L, "what", ar.what);
|
||||
break;
|
||||
case 'l':
|
||||
settabsi(L, "currentline", ar.currentline);
|
||||
break;
|
||||
case 'u':
|
||||
settabsi(L, "nups", ar.nups);
|
||||
break;
|
||||
case 'n':
|
||||
settabss(L, "name", ar.name);
|
||||
settabss(L, "namewhat", ar.namewhat);
|
||||
break;
|
||||
case 'f': opt_f = 1; break;
|
||||
case 'L': opt_L = 1; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
if (strchr(options, 'l'))
|
||||
settabsi(L, "currentline", ar.currentline);
|
||||
if (strchr(options, 'u'))
|
||||
settabsi(L, "nups", ar.nups);
|
||||
if (strchr(options, 'n')) {
|
||||
settabss(L, "name", ar.name);
|
||||
settabss(L, "namewhat", ar.namewhat);
|
||||
}
|
||||
if (strchr(options, 'L'))
|
||||
treatstackoption(L, L1, "activelines");
|
||||
if (strchr(options, 'f'))
|
||||
treatstackoption(L, L1, "func");
|
||||
return 1; /* return table */
|
||||
if (opt_L) treatstackoption(L, L1, "activelines");
|
||||
if (opt_f) treatstackoption(L, L1, "func");
|
||||
return 1; /* Return result table. */
|
||||
}
|
||||
|
||||
LJLIB_CF(debug_getlocal)
|
||||
|
@ -425,7 +425,7 @@ LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n)
|
||||
|
||||
LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
|
||||
{
|
||||
int status = 1;
|
||||
int opt_f = 0, opt_L = 0;
|
||||
TValue *frame = NULL;
|
||||
TValue *nextframe = NULL;
|
||||
GCfunc *fn;
|
||||
@ -478,35 +478,41 @@ LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
|
||||
ar->name = NULL;
|
||||
}
|
||||
} else if (*what == 'f') {
|
||||
setfuncV(L, L->top, fn);
|
||||
incr_top(L);
|
||||
opt_f = 1;
|
||||
} else if (*what == 'L') {
|
||||
if (isluafunc(fn)) {
|
||||
GCtab *t = lj_tab_new(L, 0, 0);
|
||||
GCproto *pt = funcproto(fn);
|
||||
const void *lineinfo = proto_lineinfo(pt);
|
||||
if (lineinfo) {
|
||||
BCLine first = pt->firstline;
|
||||
int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4;
|
||||
MSize i, szl = pt->sizebc-1;
|
||||
for (i = 0; i < szl; i++) {
|
||||
BCLine line = first +
|
||||
(sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] :
|
||||
sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] :
|
||||
(BCLine)((const uint32_t *)lineinfo)[i]);
|
||||
setboolV(lj_tab_setint(L, t, line), 1);
|
||||
}
|
||||
}
|
||||
settabV(L, L->top, t);
|
||||
} else {
|
||||
setnilV(L->top);
|
||||
}
|
||||
incr_top(L);
|
||||
opt_L = 1;
|
||||
} else {
|
||||
status = 0; /* Bad option. */
|
||||
return 0; /* Bad option. */
|
||||
}
|
||||
}
|
||||
return status;
|
||||
if (opt_f) {
|
||||
setfuncV(L, L->top, fn);
|
||||
incr_top(L);
|
||||
}
|
||||
if (opt_L) {
|
||||
if (isluafunc(fn)) {
|
||||
GCtab *t = lj_tab_new(L, 0, 0);
|
||||
GCproto *pt = funcproto(fn);
|
||||
const void *lineinfo = proto_lineinfo(pt);
|
||||
if (lineinfo) {
|
||||
BCLine first = pt->firstline;
|
||||
int sz = pt->numline < 256 ? 1 : pt->numline < 65536 ? 2 : 4;
|
||||
MSize i, szl = pt->sizebc-1;
|
||||
for (i = 0; i < szl; i++) {
|
||||
BCLine line = first +
|
||||
(sz == 1 ? (BCLine)((const uint8_t *)lineinfo)[i] :
|
||||
sz == 2 ? (BCLine)((const uint16_t *)lineinfo)[i] :
|
||||
(BCLine)((const uint32_t *)lineinfo)[i]);
|
||||
setboolV(lj_tab_setint(L, t, line), 1);
|
||||
}
|
||||
}
|
||||
settabV(L, L->top, t);
|
||||
} else {
|
||||
setnilV(L->top);
|
||||
}
|
||||
incr_top(L);
|
||||
}
|
||||
return 1; /* Ok. */
|
||||
}
|
||||
|
||||
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)
|
||||
|
Loading…
Reference in New Issue
Block a user