aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_client.cpp
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-09-19 20:56:13 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-09-19 20:56:13 +0200
commitc8900e169a1ddceec07a449f1ae7c4322ff02036 (patch)
tree5156605fb473d25786426eb6876ba2e7d3b7507b /src/script/cpp_api/s_client.cpp
parent950d2c9b3e10cbace9236e820c8119d1abb9e01f (diff)
parente0529da5c84f224c380e6d5e063392cb01f85683 (diff)
downloaddragonfireclient-c8900e169a1ddceec07a449f1ae7c4322ff02036.tar.xz
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'src/script/cpp_api/s_client.cpp')
-rw-r--r--src/script/cpp_api/s_client.cpp88
1 files changed, 73 insertions, 15 deletions
diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp
index 1ed273a30..5d20f547d 100644
--- a/src/script/cpp_api/s_client.cpp
+++ b/src/script/cpp_api/s_client.cpp
@@ -36,7 +36,11 @@ void ScriptApiClient::on_mods_loaded()
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_on_mods_loaded");
// Call callbacks
- runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+ try {
+ runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ }
}
void ScriptApiClient::on_shutdown()
@@ -47,7 +51,11 @@ void ScriptApiClient::on_shutdown()
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_on_shutdown");
// Call callbacks
- runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+ try {
+ runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ }
}
bool ScriptApiClient::on_sending_message(const std::string &message)
@@ -59,7 +67,12 @@ bool ScriptApiClient::on_sending_message(const std::string &message)
lua_getfield(L, -1, "registered_on_sending_chat_message");
// Call callbacks
lua_pushstring(L, message.c_str());
- runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+ try {
+ runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ return true;
+ }
return readParam<bool>(L, -1);
}
@@ -72,7 +85,12 @@ bool ScriptApiClient::on_receiving_message(const std::string &message)
lua_getfield(L, -1, "registered_on_receiving_chat_message");
// Call callbacks
lua_pushstring(L, message.c_str());
- runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+ try {
+ runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ return true;
+ }
return readParam<bool>(L, -1);
}
@@ -85,7 +103,11 @@ void ScriptApiClient::on_damage_taken(int32_t damage_amount)
lua_getfield(L, -1, "registered_on_damage_taken");
// Call callbacks
lua_pushinteger(L, damage_amount);
- runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+ try {
+ runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ }
}
void ScriptApiClient::on_hp_modification(int32_t newhp)
@@ -97,7 +119,11 @@ void ScriptApiClient::on_hp_modification(int32_t newhp)
lua_getfield(L, -1, "registered_on_hp_modification");
// Call callbacks
lua_pushinteger(L, newhp);
- runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+ try {
+ runCallbacks(1, RUN_CALLBACKS_MODE_OR_SC);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ }
}
void ScriptApiClient::on_death()
@@ -108,7 +134,11 @@ void ScriptApiClient::on_death()
lua_getglobal(L, "core");
lua_getfield(L, -1, "registered_on_death");
// Call callbacks
- runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+ try {
+ runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ }
}
void ScriptApiClient::environment_step(float dtime)
@@ -123,8 +153,7 @@ void ScriptApiClient::environment_step(float dtime)
try {
runCallbacks(1, RUN_CALLBACKS_MODE_FIRST);
} catch (LuaError &e) {
- getClient()->setFatalError(std::string("Client environment_step: ") + e.what() + "\n"
- + script_get_backtrace(L));
+ getClient()->setFatalError(e);
}
}
@@ -149,7 +178,11 @@ void ScriptApiClient::on_formspec_input(const std::string &formname,
lua_pushlstring(L, value.c_str(), value.size());
lua_settable(L, -3);
}
- runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC);
+ try {
+ runCallbacks(2, RUN_CALLBACKS_MODE_OR_SC);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ }
}
bool ScriptApiClient::on_dignode(v3s16 p, MapNode node)
@@ -167,7 +200,12 @@ bool ScriptApiClient::on_dignode(v3s16 p, MapNode node)
pushnode(L, node, ndef);
// Call functions
- runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ try {
+ runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ return true;
+ }
return lua_toboolean(L, -1);
}
@@ -186,7 +224,12 @@ bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node)
pushnode(L, node, ndef);
// Call functions
- runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ try {
+ runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ return true;
+ }
return readParam<bool>(L, -1);
}
@@ -203,7 +246,12 @@ bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefini
push_item_definition(L, item);
// Call functions
- runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ try {
+ runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ return true;
+ }
return readParam<bool>(L, -1);
}
@@ -220,7 +268,12 @@ bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &poi
push_pointed_thing(L, pointed, true);
// Call functions
- runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ try {
+ runCallbacks(2, RUN_CALLBACKS_MODE_OR);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ return true;
+ }
return readParam<bool>(L, -1);
}
@@ -348,7 +401,12 @@ bool ScriptApiClient::on_inventory_open(Inventory *inventory)
push_inventory(L, inventory);
- runCallbacks(1, RUN_CALLBACKS_MODE_OR);
+ try {
+ runCallbacks(1, RUN_CALLBACKS_MODE_OR);
+ } catch (LuaError &e) {
+ getClient()->setFatalError(e);
+ return true;
+ }
return readParam<bool>(L, -1);
}