-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhook-lua2.c
More file actions
32 lines (26 loc) · 661 Bytes
/
hook-lua2.c
File metadata and controls
32 lines (26 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <lauxlib.h>
#include <lua.h>
#include <lualib.h>
#include <stdio.h>
static int trace(lua_State *l)
{
lua_Debug ar;
if (lua_getstack(l, 1, &ar) && lua_getinfo(l, "Snl", &ar))
{
printf("Function (%s): %s\n", ar.what, ar.name ? ar.name : "(no name)");
printf("Source: %s\n", ar.short_src);
printf("Line: %d\n", ar.currentline);
}
return 0;
}
int main(void)
{
lua_State *l = luaL_newstate();
luaL_openlibs(l);
const char *luaCode = "function jj()\nprint('Hello from Lua!')\ntrace()\nend";
luaL_dostring(l, luaCode);
lua_register(l, "trace", trace);
lua_getglobal(l, "jj");
lua_pcall(l, 0, 0, 0);
lua_close(l);
}