File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change 11#include "debugger.h"
22
3- #include <stdio.h>
43#include <lua.h>
54
5+ #include <stdio.h>
6+ #include <stdlib.h>
7+ #include <string.h>
8+
69#include "laco.h"
10+ #include "util.h"
711
812void laco_print_debug_info (struct LacoState * laco ,
913 const char * function_name ) {
10- lua_State * L = laco_get_laco_lua_state (laco );
14+ int i ;
15+ char * namespace ;
16+ lua_State * L = laco_get_laco_lua_state (laco );
17+ size_t index = LUA_GLOBALSINDEX ;
1118 lua_Debug debug_info = {0 };
1219
13- lua_getfield (L , LUA_GLOBALSINDEX , function_name );
20+ char * name = strdup (function_name );
21+ char * * namespaces = laco_split_by ("." , name , 0 );
22+
23+ /* Walk down the namespace if there is something to go down */
24+ for (i = 0 ; (namespace = namespaces [i ]); i ++ ) {
25+ lua_getfield (L , index , namespace );
26+ index = lua_gettop (L );
27+ }
1428
1529 lua_getinfo (L , ">Sl" , & debug_info );
1630
@@ -21,4 +35,12 @@ void laco_print_debug_info(struct LacoState* laco,
2135 "Current line: \t%d\n" ,
2236 debug_info .what , debug_info .source ,
2337 debug_info .linedefined , debug_info .currentline );
38+
39+ /* Pop off the extra fields from the top of the stack */
40+ if (i > 1 ) {
41+ lua_pop (L , i - 1 );
42+ }
43+
44+ free (name );
45+ free (namespaces );
2446}
You can’t perform that action at this time.
0 commit comments