Commit 9cce77aa authored by Thaodan's avatar Thaodan

[sb2] Catch lua errors. Contributes to JB#52528

Instead of using `lua_call` use `lua_pcall` to exit gracefully in case we
hit any lua errors.
parent 652a506f
......@@ -66,21 +66,39 @@ static void load_and_execute_lua_file(const char *filename)
switch(luaL_loadfile(sb2d_lua, filename)) {
case LUA_ERRFILE:
fprintf(stderr, "Error loading %s\n", filename);
exit(1);
fprintf(stderr, "Error loading %s\n", filename);
exit(EXIT_FAILURE);
case LUA_ERRSYNTAX:
errmsg = lua_tostring(sb2d_lua, -1);
errmsg = lua_tostring(sb2d_lua, -1);
fprintf(stderr, "Syntax error in %s (%s)\n", filename,
(errmsg?errmsg:""));
exit(1);
exit(EXIT_FAILURE);
case LUA_ERRMEM:
fprintf(stderr, "Memory allocation error while "
"loading %s\n", filename);
exit(1);
default:
;
"loading %s\n", filename);
exit(EXIT_FAILURE);
case LUA_OK:
break;
default:
fprintf(stderr, "Unknown LUA error "
"loading %s\n", filename);
exit(EXIT_FAILURE);
}
switch(lua_pcall(sb2d_lua, 0, 0, 0)) {
case LUA_ERRRUN:
fprintf(stderr, "Runtime-Error loading %s (%s)\n",
filename, lua_tostring(sb2d_lua, -1));
exit(EXIT_FAILURE);
case LUA_ERRMEM:
fprintf(stderr, "Memory allocation error while "
"loading %s (%s) \n",
filename, lua_tostring(sb2d_lua, -1));
exit(EXIT_FAILURE);
case LUA_OK:
return;
}
lua_call(sb2d_lua, 0, 0);
exit(1);
}
/* Lua calls this at panic: */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment