Skip to content
Snippets Groups Projects
Commit 51d56f84 authored by Ilya's avatar Ilya Committed by Konstantin Osipov
Browse files

lua: set lua_atpanic with custom handler

Set lua_atpanic with handler which prints line and file
where panic occured

But in some cases luajit doesn't call this function, though
program fails

Investigation shows that it happens inside unwind library
parent b4bf3fa0
No related branches found
No related tags found
No related merge requests found
......@@ -314,6 +314,16 @@ tarantool_lua_setpaths(struct lua_State *L)
lua_pop(L, 1); /* package */
}
static int
tarantool_panic_handler(lua_State *L) {
const char *problem = lua_tostring(L, -1);
lua_Debug ar;
lua_getstack(L, 1, &ar);
lua_getinfo(L, "nSl", &ar);
say_crit("%s at %s:%d \n", problem, ar.short_src, ar.currentline);
return 1;
}
static int
luaopen_tarantool(lua_State *L)
{
......@@ -377,7 +387,6 @@ tarantool_lua_init(const char *tarantool_bin, int argc, char **argv)
/* Initialize ffi to enable luaL_pushcdata/luaL_checkcdata functions */
luaL_loadstring(L, "return require('ffi')");
lua_call(L, 0, 0);
lua_register(L, "tonumber64", lbox_tonumber64);
tarantool_lua_utils_init(L);
......@@ -446,6 +455,7 @@ tarantool_lua_init(const char *tarantool_bin, int argc, char **argv)
panic("Failed to unload 'strict' Lua module");
#endif /* NDEBUG */
lua_atpanic(L, tarantool_panic_handler);
/* clear possible left-overs of init */
lua_settop(L, 0);
tarantool_L = L;
......@@ -590,6 +600,7 @@ tarantool_lua_run_script(char *path, bool interactive,
* To work this problem around we must run init script in
* a separate fiber.
*/
script_fiber = fiber_new(title, run_script_f);
if (script_fiber == NULL)
panic("%s", diag_last_error(diag_get())->errmsg);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment