mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Clean up/improve some scriptapi error handling code
This commit is contained in:
parent
7423c4c11e
commit
766e885a1b
11 changed files with 120 additions and 94 deletions
|
@ -53,13 +53,7 @@ void ScriptApiEnv::environment_Step(float dtime)
|
|||
lua_getfield(L, -1, "registered_globalsteps");
|
||||
// Call callbacks
|
||||
lua_pushnumber(L, dtime);
|
||||
try {
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
|
||||
} catch (LuaError &e) {
|
||||
getServer()->setAsyncFatalError(
|
||||
std::string("environment_Step: ") + e.what() + "\n"
|
||||
+ script_get_backtrace(L));
|
||||
}
|
||||
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
|
||||
void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &type)
|
||||
|
@ -76,13 +70,7 @@ void ScriptApiEnv::player_event(ServerActiveObject *player, const std::string &t
|
|||
// Call callbacks
|
||||
objectrefGetOrCreate(L, player); // player
|
||||
lua_pushstring(L,type.c_str()); // event type
|
||||
try {
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
||||
} catch (LuaError &e) {
|
||||
getServer()->setAsyncFatalError(
|
||||
std::string("player_event: ") + e.what() + "\n"
|
||||
+ script_get_backtrace(L) );
|
||||
}
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
|
||||
void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
|
||||
|
@ -257,9 +245,8 @@ void ScriptApiEnv::on_emerge_area_completion(
|
|||
try {
|
||||
PCALL_RES(lua_pcall(L, 4, 0, error_handler));
|
||||
} catch (LuaError &e) {
|
||||
server->setAsyncFatalError(
|
||||
std::string("on_emerge_area_completion: ") + e.what() + "\n"
|
||||
+ script_get_backtrace(L));
|
||||
// Note: don't throw here, we still need to run the cleanup code below
|
||||
server->setAsyncFatalError(e);
|
||||
}
|
||||
|
||||
lua_pop(L, 1); // Pop error handler
|
||||
|
@ -300,4 +287,4 @@ void ScriptApiEnv::on_liquid_transformed(
|
|||
}
|
||||
|
||||
runCallbacks(2, RUN_CALLBACKS_MODE_FIRST);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue