@@ -33,7 +33,11 @@ void ScriptApiClient::on_mods_loaded()
33
33
lua_getglobal (L, " core" );
34
34
lua_getfield (L, -1 , " registered_on_mods_loaded" );
35
35
// Call callbacks
36
- runCallbacks (0 , RUN_CALLBACKS_MODE_FIRST);
36
+ try {
37
+ runCallbacks (0 , RUN_CALLBACKS_MODE_FIRST);
38
+ } catch (LuaError &e) {
39
+ getClient ()->setFatalError (e);
40
+ }
37
41
}
38
42
39
43
void ScriptApiClient::on_shutdown ()
@@ -44,7 +48,11 @@ void ScriptApiClient::on_shutdown()
44
48
lua_getglobal (L, " core" );
45
49
lua_getfield (L, -1 , " registered_on_shutdown" );
46
50
// Call callbacks
47
- runCallbacks (0 , RUN_CALLBACKS_MODE_FIRST);
51
+ try {
52
+ runCallbacks (0 , RUN_CALLBACKS_MODE_FIRST);
53
+ } catch (LuaError &e) {
54
+ getClient ()->setFatalError (e);
55
+ }
48
56
}
49
57
50
58
bool ScriptApiClient::on_sending_message (const std::string &message)
@@ -56,7 +64,12 @@ bool ScriptApiClient::on_sending_message(const std::string &message)
56
64
lua_getfield (L, -1 , " registered_on_sending_chat_message" );
57
65
// Call callbacks
58
66
lua_pushstring (L, message.c_str ());
59
- runCallbacks (1 , RUN_CALLBACKS_MODE_OR_SC);
67
+ try {
68
+ runCallbacks (1 , RUN_CALLBACKS_MODE_OR_SC);
69
+ } catch (LuaError &e) {
70
+ getClient ()->setFatalError (e);
71
+ return true ;
72
+ }
60
73
return readParam<bool >(L, -1 );
61
74
}
62
75
@@ -69,7 +82,12 @@ bool ScriptApiClient::on_receiving_message(const std::string &message)
69
82
lua_getfield (L, -1 , " registered_on_receiving_chat_message" );
70
83
// Call callbacks
71
84
lua_pushstring (L, message.c_str ());
72
- runCallbacks (1 , RUN_CALLBACKS_MODE_OR_SC);
85
+ try {
86
+ runCallbacks (1 , RUN_CALLBACKS_MODE_OR_SC);
87
+ } catch (LuaError &e) {
88
+ getClient ()->setFatalError (e);
89
+ return true ;
90
+ }
73
91
return readParam<bool >(L, -1 );
74
92
}
75
93
@@ -82,7 +100,11 @@ void ScriptApiClient::on_damage_taken(int32_t damage_amount)
82
100
lua_getfield (L, -1 , " registered_on_damage_taken" );
83
101
// Call callbacks
84
102
lua_pushinteger (L, damage_amount);
85
- runCallbacks (1 , RUN_CALLBACKS_MODE_OR_SC);
103
+ try {
104
+ runCallbacks (1 , RUN_CALLBACKS_MODE_OR_SC);
105
+ } catch (LuaError &e) {
106
+ getClient ()->setFatalError (e);
107
+ }
86
108
}
87
109
88
110
void ScriptApiClient::on_hp_modification (int32_t newhp)
@@ -94,7 +116,11 @@ void ScriptApiClient::on_hp_modification(int32_t newhp)
94
116
lua_getfield (L, -1 , " registered_on_hp_modification" );
95
117
// Call callbacks
96
118
lua_pushinteger (L, newhp);
97
- runCallbacks (1 , RUN_CALLBACKS_MODE_OR_SC);
119
+ try {
120
+ runCallbacks (1 , RUN_CALLBACKS_MODE_OR_SC);
121
+ } catch (LuaError &e) {
122
+ getClient ()->setFatalError (e);
123
+ }
98
124
}
99
125
100
126
void ScriptApiClient::on_death ()
@@ -105,7 +131,11 @@ void ScriptApiClient::on_death()
105
131
lua_getglobal (L, " core" );
106
132
lua_getfield (L, -1 , " registered_on_death" );
107
133
// Call callbacks
108
- runCallbacks (0 , RUN_CALLBACKS_MODE_FIRST);
134
+ try {
135
+ runCallbacks (0 , RUN_CALLBACKS_MODE_FIRST);
136
+ } catch (LuaError &e) {
137
+ getClient ()->setFatalError (e);
138
+ }
109
139
}
110
140
111
141
void ScriptApiClient::environment_step (float dtime)
@@ -120,8 +150,7 @@ void ScriptApiClient::environment_step(float dtime)
120
150
try {
121
151
runCallbacks (1 , RUN_CALLBACKS_MODE_FIRST);
122
152
} catch (LuaError &e) {
123
- getClient ()->setFatalError (std::string (" Client environment_step: " ) + e.what () + " \n "
124
- + script_get_backtrace (L));
153
+ getClient ()->setFatalError (e);
125
154
}
126
155
}
127
156
@@ -146,7 +175,11 @@ void ScriptApiClient::on_formspec_input(const std::string &formname,
146
175
lua_pushlstring (L, value.c_str (), value.size ());
147
176
lua_settable (L, -3 );
148
177
}
149
- runCallbacks (2 , RUN_CALLBACKS_MODE_OR_SC);
178
+ try {
179
+ runCallbacks (2 , RUN_CALLBACKS_MODE_OR_SC);
180
+ } catch (LuaError &e) {
181
+ getClient ()->setFatalError (e);
182
+ }
150
183
}
151
184
152
185
bool ScriptApiClient::on_dignode (v3s16 p, MapNode node)
@@ -164,7 +197,12 @@ bool ScriptApiClient::on_dignode(v3s16 p, MapNode node)
164
197
pushnode (L, node, ndef);
165
198
166
199
// Call functions
167
- runCallbacks (2 , RUN_CALLBACKS_MODE_OR);
200
+ try {
201
+ runCallbacks (2 , RUN_CALLBACKS_MODE_OR);
202
+ } catch (LuaError &e) {
203
+ getClient ()->setFatalError (e);
204
+ return true ;
205
+ }
168
206
return lua_toboolean (L, -1 );
169
207
}
170
208
@@ -183,7 +221,12 @@ bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node)
183
221
pushnode (L, node, ndef);
184
222
185
223
// Call functions
186
- runCallbacks (2 , RUN_CALLBACKS_MODE_OR);
224
+ try {
225
+ runCallbacks (2 , RUN_CALLBACKS_MODE_OR);
226
+ } catch (LuaError &e) {
227
+ getClient ()->setFatalError (e);
228
+ return true ;
229
+ }
187
230
return readParam<bool >(L, -1 );
188
231
}
189
232
@@ -200,7 +243,12 @@ bool ScriptApiClient::on_placenode(const PointedThing &pointed, const ItemDefini
200
243
push_item_definition (L, item);
201
244
202
245
// Call functions
203
- runCallbacks (2 , RUN_CALLBACKS_MODE_OR);
246
+ try {
247
+ runCallbacks (2 , RUN_CALLBACKS_MODE_OR);
248
+ } catch (LuaError &e) {
249
+ getClient ()->setFatalError (e);
250
+ return true ;
251
+ }
204
252
return readParam<bool >(L, -1 );
205
253
}
206
254
@@ -217,7 +265,12 @@ bool ScriptApiClient::on_item_use(const ItemStack &item, const PointedThing &poi
217
265
push_pointed_thing (L, pointed, true );
218
266
219
267
// Call functions
220
- runCallbacks (2 , RUN_CALLBACKS_MODE_OR);
268
+ try {
269
+ runCallbacks (2 , RUN_CALLBACKS_MODE_OR);
270
+ } catch (LuaError &e) {
271
+ getClient ()->setFatalError (e);
272
+ return true ;
273
+ }
221
274
return readParam<bool >(L, -1 );
222
275
}
223
276
@@ -238,7 +291,12 @@ bool ScriptApiClient::on_inventory_open(Inventory *inventory)
238
291
lua_rawset (L, -3 );
239
292
}
240
293
241
- runCallbacks (1 , RUN_CALLBACKS_MODE_OR);
294
+ try {
295
+ runCallbacks (1 , RUN_CALLBACKS_MODE_OR);
296
+ } catch (LuaError &e) {
297
+ getClient ()->setFatalError (e);
298
+ return true ;
299
+ }
242
300
return readParam<bool >(L, -1 );
243
301
}
244
302
0 commit comments