Skip to content

Commit 4a63eaf

Browse files
committed
Add a basic debug info command
1 parent 81da743 commit 4a63eaf

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/commands/debugger.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "debugger.h"
2+
3+
#include <stdio.h>
4+
#include <lua.h>
5+
6+
#include "laco.h"
7+
8+
void laco_print_debug_info(struct LacoState* laco,
9+
const char* function_name) {
10+
lua_State* L = laco_get_laco_lua_state(laco);
11+
lua_Debug debug_info = {0};
12+
13+
lua_getfield(L, LUA_GLOBALSINDEX, function_name);
14+
15+
lua_getinfo(L, ">Sl", &debug_info);
16+
17+
printf(
18+
"What: \t%s\n"
19+
"Source file: \t%s\n"
20+
"Line defined on: \t%d\n"
21+
"Current line: \t%d\n",
22+
debug_info.what, debug_info.source,
23+
debug_info.linedefined, debug_info.currentline);
24+
}

src/commands/debugger.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef LACO_DEBUGGER_H
2+
#define LACO_DEBUGGER_H
3+
4+
struct LacoState;
5+
6+
void laco_print_debug_info(struct LacoState* laco,
7+
const char* function_name);
8+
9+
#endif /* LACO_DEBUGGER_H */

0 commit comments

Comments
 (0)