Print stack traceback in case of error.
This commit is contained in:
parent
1f79e2d345
commit
d7966dbe2d
20
src/lua.c
20
src/lua.c
|
@ -16,6 +16,7 @@ extern struct sessionhead sessions;
|
||||||
static lua_State *lua; /* Lua interpreter state. */
|
static lua_State *lua; /* Lua interpreter state. */
|
||||||
|
|
||||||
|
|
||||||
|
static int traceback_handler(lua_State *lua);
|
||||||
void init_options(void);
|
void init_options(void);
|
||||||
void interactive_mode(void);
|
void interactive_mode(void);
|
||||||
|
|
||||||
|
@ -77,8 +78,11 @@ start_lua()
|
||||||
"=<command line>") || lua_pcall(lua, 0, LUA_MULTRET, 0))
|
"=<command line>") || lua_pcall(lua, 0, LUA_MULTRET, 0))
|
||||||
fatal(ERROR_CONFIG, "%s\n", lua_tostring(lua, -1));
|
fatal(ERROR_CONFIG, "%s\n", lua_tostring(lua, -1));
|
||||||
} else {
|
} else {
|
||||||
if (luaL_loadfile(lua, opts.config) ||
|
if (luaL_loadfile(lua, opts.config))
|
||||||
lua_pcall(lua, 0, LUA_MULTRET, 0))
|
fatal(ERROR_CONFIG, "%s\n", lua_tostring(lua, -1));
|
||||||
|
lua_pushcfunction(lua, traceback_handler);
|
||||||
|
lua_insert(lua, 1);
|
||||||
|
if (lua_pcall(lua, 0, LUA_MULTRET, -2))
|
||||||
fatal(ERROR_CONFIG, "%s\n", lua_tostring(lua, -1));
|
fatal(ERROR_CONFIG, "%s\n", lua_tostring(lua, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +91,18 @@ start_lua()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add a stack traceback to the error message.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
traceback_handler(lua_State *lua)
|
||||||
|
{
|
||||||
|
|
||||||
|
luaL_traceback(lua, lua, lua_tostring(lua, 1), 0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Stop the Lua interpreter.
|
* Stop the Lua interpreter.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue