diff options
author | Alex Auvolat <alex@adnab.me> | 2017-05-09 19:29:06 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2017-05-09 19:29:06 +0200 |
commit | 83cc53def0abb6f44ebd95a7175e717e3c66cd48 (patch) | |
tree | 87e7beecd0f3f059a4a61ba0c819d2883846cee2 /src/sysbin/lx/main.c | |
parent | d1aed44edf1bd6ab9cc11d7c8796051a5ae8e79d (diff) | |
download | kogata-83cc53def0abb6f44ebd95a7175e717e3c66cd48.tar.gz kogata-83cc53def0abb6f44ebd95a7175e717e3c66cd48.zip |
Grids & lua debugging
Diffstat (limited to 'src/sysbin/lx/main.c')
-rw-r--r-- | src/sysbin/lx/main.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/sysbin/lx/main.c b/src/sysbin/lx/main.c index 573e1bb..d758285 100644 --- a/src/sysbin/lx/main.c +++ b/src/sysbin/lx/main.c @@ -106,6 +106,7 @@ void laction (int i) { ** (if present) */ void l_message (const char *pname, const char *msg) { + dbg_print(msg); if (pname) lua_writestringerror("%s: ", pname); lua_writestringerror("%s\n", msg); } @@ -393,6 +394,17 @@ int pmain (lua_State *L) { return 1; } +int lxtraceback (lua_State *L) { + lua_pushstring(L, "\n"); + lua_getglobal(L, "debug"); + lua_getfield(L, -1, "traceback"); + lua_remove(L, -2); + lua_call(L, 0, 1); + lua_pushstring(L, "\n"); + lua_concat(L, 4); + return 1; +} + int main (int argc, char **argv) { int status, result; @@ -401,8 +413,10 @@ int main (int argc, char **argv) { l_message(argv[0], "cannot create state: not enough memory"); return EXIT_FAILURE; } + lua_pushcfunction(L, &lxtraceback); + int traceback_pos = lua_gettop(L); lua_pushcfunction(L, &pmain); /* to call 'pmain' in protected mode */ - status = lua_pcall(L, 0, 1, 0); /* do the call */ + status = lua_pcall(L, 0, 1, traceback_pos); /* do the call */ result = lua_toboolean(L, -1); /* get result */ report(L, status); lua_close(L); |