#include "s_client.h"
#include "s_internal.h"
-#include "client.h"
+#include "client/client.h"
#include "common/c_converter.h"
#include "common/c_content.h"
#include "s_item.h"
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()
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)
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);
}
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);
}
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)
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()
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)
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);
}
}
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)
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);
}
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);
}
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);
}
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);
}
lua_rawset(L, -3);
}
- 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);
}