diff options
-rw-r--r-- | src/Makefile.dep | 2 | ||||
-rw-r--r-- | src/lib_debug.c | 15 | ||||
-rw-r--r-- | src/lj_debug.c | 17 | ||||
-rw-r--r-- | src/lj_debug.h | 20 |
4 files changed, 49 insertions, 5 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep index 94a963ba..e00ba2f6 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep | |||
@@ -8,7 +8,7 @@ lib_base.o: lib_base.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ | |||
8 | lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ | 8 | lib_bit.o: lib_bit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ |
9 | lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_lib.h lj_libdef.h | 9 | lj_arch.h lj_err.h lj_errmsg.h lj_str.h lj_lib.h lj_libdef.h |
10 | lib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ | 10 | lib_debug.o: lib_debug.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \ |
11 | lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_lib.h lj_libdef.h | 11 | lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_debug.h lj_lib.h lj_libdef.h |
12 | lib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ | 12 | lib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ |
13 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h \ | 13 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_meta.h \ |
14 | lj_ctype.h lj_cparse.h lj_cdata.h lj_cconv.h lj_carith.h lj_ccall.h \ | 14 | lj_ctype.h lj_cparse.h lj_cdata.h lj_cconv.h lj_carith.h lj_ccall.h \ |
diff --git a/src/lib_debug.c b/src/lib_debug.c index ab504de7..d90c422f 100644 --- a/src/lib_debug.c +++ b/src/lib_debug.c | |||
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | #include "lj_obj.h" | 16 | #include "lj_obj.h" |
17 | #include "lj_err.h" | 17 | #include "lj_err.h" |
18 | #include "lj_debug.h" | ||
18 | #include "lj_lib.h" | 19 | #include "lj_lib.h" |
19 | 20 | ||
20 | /* ------------------------------------------------------------------------ */ | 21 | /* ------------------------------------------------------------------------ */ |
@@ -77,6 +78,12 @@ static void settabsi(lua_State *L, const char *i, int v) | |||
77 | lua_setfield(L, -2, i); | 78 | lua_setfield(L, -2, i); |
78 | } | 79 | } |
79 | 80 | ||
81 | static void settabsb(lua_State *L, const char *i, int v) | ||
82 | { | ||
83 | lua_pushboolean(L, v); | ||
84 | lua_setfield(L, -2, i); | ||
85 | } | ||
86 | |||
80 | static lua_State *getthread(lua_State *L, int *arg) | 87 | static lua_State *getthread(lua_State *L, int *arg) |
81 | { | 88 | { |
82 | if (L->base < L->top && tvisthread(L->base)) { | 89 | if (L->base < L->top && tvisthread(L->base)) { |
@@ -101,12 +108,12 @@ static void treatstackoption(lua_State *L, lua_State *L1, const char *fname) | |||
101 | 108 | ||
102 | LJLIB_CF(debug_getinfo) | 109 | LJLIB_CF(debug_getinfo) |
103 | { | 110 | { |
104 | lua_Debug ar; | 111 | lj_Debug ar; |
105 | int arg, opt_f = 0, opt_L = 0; | 112 | int arg, opt_f = 0, opt_L = 0; |
106 | lua_State *L1 = getthread(L, &arg); | 113 | lua_State *L1 = getthread(L, &arg); |
107 | const char *options = luaL_optstring(L, arg+2, "flnSu"); | 114 | const char *options = luaL_optstring(L, arg+2, "flnSu"); |
108 | if (lua_isnumber(L, arg+1)) { | 115 | if (lua_isnumber(L, arg+1)) { |
109 | if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { | 116 | if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), (lua_Debug *)&ar)) { |
110 | setnilV(L->top-1); | 117 | setnilV(L->top-1); |
111 | return 1; | 118 | return 1; |
112 | } | 119 | } |
@@ -116,7 +123,7 @@ LJLIB_CF(debug_getinfo) | |||
116 | } else { | 123 | } else { |
117 | lj_err_arg(L, arg+1, LJ_ERR_NOFUNCL); | 124 | lj_err_arg(L, arg+1, LJ_ERR_NOFUNCL); |
118 | } | 125 | } |
119 | if (!lua_getinfo(L1, options, &ar)) | 126 | if (!lj_debug_getinfo(L1, options, &ar, 1)) |
120 | lj_err_arg(L, arg+2, LJ_ERR_INVOPT); | 127 | lj_err_arg(L, arg+2, LJ_ERR_INVOPT); |
121 | lua_createtable(L, 0, 16); /* Create result table. */ | 128 | lua_createtable(L, 0, 16); /* Create result table. */ |
122 | for (; *options; options++) { | 129 | for (; *options; options++) { |
@@ -133,6 +140,8 @@ LJLIB_CF(debug_getinfo) | |||
133 | break; | 140 | break; |
134 | case 'u': | 141 | case 'u': |
135 | settabsi(L, "nups", ar.nups); | 142 | settabsi(L, "nups", ar.nups); |
143 | settabsi(L, "nparams", ar.nparams); | ||
144 | settabsb(L, "isvararg", ar.isvararg); | ||
136 | break; | 145 | break; |
137 | case 'n': | 146 | case 'n': |
138 | settabss(L, "name", ar.name); | 147 | settabss(L, "name", ar.name); |
diff --git a/src/lj_debug.c b/src/lj_debug.c index 7dba8072..0e26cd7c 100644 --- a/src/lj_debug.c +++ b/src/lj_debug.c | |||
@@ -423,7 +423,7 @@ LUA_API const char *lua_setlocal(lua_State *L, const lua_Debug *ar, int n) | |||
423 | return name; | 423 | return name; |
424 | } | 424 | } |
425 | 425 | ||
426 | LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) | 426 | int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, int ext) |
427 | { | 427 | { |
428 | int opt_f = 0, opt_L = 0; | 428 | int opt_f = 0, opt_L = 0; |
429 | TValue *frame = NULL; | 429 | TValue *frame = NULL; |
@@ -471,6 +471,16 @@ LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) | |||
471 | ar->currentline = frame ? debug_frameline(L, fn, nextframe) : -1; | 471 | ar->currentline = frame ? debug_frameline(L, fn, nextframe) : -1; |
472 | } else if (*what == 'u') { | 472 | } else if (*what == 'u') { |
473 | ar->nups = fn->c.nupvalues; | 473 | ar->nups = fn->c.nupvalues; |
474 | if (ext) { | ||
475 | if (isluafunc(fn)) { | ||
476 | GCproto *pt = funcproto(fn); | ||
477 | ar->nparams = pt->numparams; | ||
478 | ar->isvararg = !!(pt->flags & PROTO_VARARG); | ||
479 | } else { | ||
480 | ar->nparams = 0; | ||
481 | ar->isvararg = 1; | ||
482 | } | ||
483 | } | ||
474 | } else if (*what == 'n') { | 484 | } else if (*what == 'n') { |
475 | ar->namewhat = frame ? lj_debug_funcname(L, frame, &ar->name) : NULL; | 485 | ar->namewhat = frame ? lj_debug_funcname(L, frame, &ar->name) : NULL; |
476 | if (ar->namewhat == NULL) { | 486 | if (ar->namewhat == NULL) { |
@@ -515,6 +525,11 @@ LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) | |||
515 | return 1; /* Ok. */ | 525 | return 1; /* Ok. */ |
516 | } | 526 | } |
517 | 527 | ||
528 | LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar) | ||
529 | { | ||
530 | return lj_debug_getinfo(L, what, (lj_Debug *)ar, 0); | ||
531 | } | ||
532 | |||
518 | LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar) | 533 | LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar) |
519 | { | 534 | { |
520 | int size; | 535 | int size; |
diff --git a/src/lj_debug.h b/src/lj_debug.h index e00769ae..48e6a229 100644 --- a/src/lj_debug.h +++ b/src/lj_debug.h | |||
@@ -8,6 +8,24 @@ | |||
8 | 8 | ||
9 | #include "lj_obj.h" | 9 | #include "lj_obj.h" |
10 | 10 | ||
11 | typedef struct lj_Debug { | ||
12 | /* Common fields. Must be in the same order as in lua.h. */ | ||
13 | int event; | ||
14 | const char *name; | ||
15 | const char *namewhat; | ||
16 | const char *what; | ||
17 | const char *source; | ||
18 | int currentline; | ||
19 | int nups; | ||
20 | int linedefined; | ||
21 | int lastlinedefined; | ||
22 | char short_src[LUA_IDSIZE]; | ||
23 | int i_ci; | ||
24 | /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/ | ||
25 | int nparams; | ||
26 | int isvararg; | ||
27 | } lj_Debug; | ||
28 | |||
11 | LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size); | 29 | LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size); |
12 | LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc); | 30 | LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc); |
13 | LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx); | 31 | LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx); |
@@ -20,6 +38,8 @@ LJ_FUNC void lj_debug_shortname(char *out, GCstr *str); | |||
20 | LJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg, | 38 | LJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg, |
21 | cTValue *frame, cTValue *nextframe); | 39 | cTValue *frame, cTValue *nextframe); |
22 | LJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc); | 40 | LJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc); |
41 | LJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, | ||
42 | int ext); | ||
23 | 43 | ||
24 | /* Fixed internal variable names. */ | 44 | /* Fixed internal variable names. */ |
25 | #define VARNAMEDEF(_) \ | 45 | #define VARNAMEDEF(_) \ |