Skip to content

Commit 4235280

Browse files
committed
Add ablity to look through named tables
1 parent ab161a6 commit 4235280

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/commands/debugger.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
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

812
void 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
}

0 commit comments

Comments
 (0)