From 83cc53def0abb6f44ebd95a7175e717e3c66cd48 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 9 May 2017 19:29:06 +0200 Subject: Grids & lua debugging --- src/sysbin/lx/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/sysbin/lx/main.c') 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); -- cgit v1.2.3