Fix 'f' and 'L' options for debug.getinfo() and lua_getinfo().

This commit is contained in:
Mike Pall 2012-09-20 15:19:48 +02:00
parent 2d3c1967c7
commit 965694b0af
2 changed files with 60 additions and 47 deletions

View File

@ -102,7 +102,7 @@ static void treatstackoption(lua_State *L, lua_State *L1, const char *fname)
LJLIB_CF(debug_getinfo) LJLIB_CF(debug_getinfo)
{ {
lua_Debug ar; lua_Debug ar;
int arg; int arg, opt_f = 0, opt_L = 0;
lua_State *L1 = getthread(L, &arg); lua_State *L1 = getthread(L, &arg);
const char *options = luaL_optstring(L, arg+2, "flnSu"); const char *options = luaL_optstring(L, arg+2, "flnSu");
if (lua_isnumber(L, arg+1)) { if (lua_isnumber(L, arg+1)) {
@ -118,27 +118,34 @@ LJLIB_CF(debug_getinfo)
} }
if (!lua_getinfo(L1, options, &ar)) if (!lua_getinfo(L1, options, &ar))
lj_err_arg(L, arg+2, LJ_ERR_INVOPT); lj_err_arg(L, arg+2, LJ_ERR_INVOPT);
lua_createtable(L, 0, 16); lua_createtable(L, 0, 16); /* Create result table. */
if (strchr(options, 'S')) { for (; *options; options++) {
switch (*options) {
case 'S':
settabss(L, "source", ar.source); settabss(L, "source", ar.source);
settabss(L, "short_src", ar.short_src); settabss(L, "short_src", ar.short_src);
settabsi(L, "linedefined", ar.linedefined); settabsi(L, "linedefined", ar.linedefined);
settabsi(L, "lastlinedefined", ar.lastlinedefined); settabsi(L, "lastlinedefined", ar.lastlinedefined);
settabss(L, "what", ar.what); settabss(L, "what", ar.what);
} break;
if (strchr(options, 'l')) case 'l':
settabsi(L, "currentline", ar.currentline); settabsi(L, "currentline", ar.currentline);
if (strchr(options, 'u')) break;
case 'u':
settabsi(L, "nups", ar.nups); settabsi(L, "nups", ar.nups);
if (strchr(options, 'n')) { break;
case 'n':
settabss(L, "name", ar.name); settabss(L, "name", ar.name);
settabss(L, "namewhat", ar.namewhat); settabss(L, "namewhat", ar.namewhat);
break;
case 'f': opt_f = 1; break;
case 'L': opt_L = 1; break;
default: break;
} }
if (strchr(options, 'L')) }
treatstackoption(L, L1, "activelines"); if (opt_L) treatstackoption(L, L1, "activelines");
if (strchr(options, 'f')) if (opt_f) treatstackoption(L, L1, "func");
treatstackoption(L, L1, "func"); return 1; /* Return result table. */
return 1; /* return table */
} }
LJLIB_CF(debug_getlocal) LJLIB_CF(debug_getlocal)

View File

@ -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) 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 *frame = NULL;
TValue *nextframe = NULL; TValue *nextframe = NULL;
GCfunc *fn; GCfunc *fn;
@ -478,9 +478,18 @@ LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
ar->name = NULL; ar->name = NULL;
} }
} else if (*what == 'f') { } else if (*what == 'f') {
opt_f = 1;
} else if (*what == 'L') {
opt_L = 1;
} else {
return 0; /* Bad option. */
}
}
if (opt_f) {
setfuncV(L, L->top, fn); setfuncV(L, L->top, fn);
incr_top(L); incr_top(L);
} else if (*what == 'L') { }
if (opt_L) {
if (isluafunc(fn)) { if (isluafunc(fn)) {
GCtab *t = lj_tab_new(L, 0, 0); GCtab *t = lj_tab_new(L, 0, 0);
GCproto *pt = funcproto(fn); GCproto *pt = funcproto(fn);
@ -502,11 +511,8 @@ LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
setnilV(L->top); setnilV(L->top);
} }
incr_top(L); incr_top(L);
} else {
status = 0; /* Bad option. */
} }
} return 1; /* Ok. */
return status;
} }
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar) LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)