Print stack traceback in case of error.

This commit is contained in:
Lefteris Chatzimparmpas 2012-11-18 23:09:29 +01:00
parent 1f79e2d345
commit d7966dbe2d

View File

@ -16,6 +16,7 @@ extern struct sessionhead sessions;
static lua_State *lua; /* Lua interpreter state. */
static int traceback_handler(lua_State *lua);
void init_options(void);
void interactive_mode(void);
@ -77,8 +78,11 @@ start_lua()
"=<command line>") || lua_pcall(lua, 0, LUA_MULTRET, 0))
fatal(ERROR_CONFIG, "%s\n", lua_tostring(lua, -1));
} else {
if (luaL_loadfile(lua, opts.config) ||
lua_pcall(lua, 0, LUA_MULTRET, 0))
if (luaL_loadfile(lua, opts.config))
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));
}
@ -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.
*/