@@ -47,8 +47,13 @@ bool ScriptApiItem::item_OnDrop(ItemStack &item,
47
47
pushFloatPos (L, pos);
48
48
if (lua_pcall (L, 3 , 1 , errorhandler))
49
49
scriptError ();
50
- if (!lua_isnil (L, -1 ))
51
- item = read_item (L,-1 , getServer ());
50
+ if (!lua_isnil (L, -1 )) {
51
+ try {
52
+ item = read_item (L,-1 , getServer ());
53
+ } catch (LuaError &e) {
54
+ throw LuaError (std::string (e.what ()) + " . item=" + item.name );
55
+ }
56
+ }
52
57
lua_pop (L, 2 ); // Pop item and error handler
53
58
return true ;
54
59
}
@@ -71,8 +76,13 @@ bool ScriptApiItem::item_OnPlace(ItemStack &item,
71
76
pushPointedThing (pointed);
72
77
if (lua_pcall (L, 3 , 1 , errorhandler))
73
78
scriptError ();
74
- if (!lua_isnil (L, -1 ))
75
- item = read_item (L,-1 , getServer ());
79
+ if (!lua_isnil (L, -1 )) {
80
+ try {
81
+ item = read_item (L,-1 , getServer ());
82
+ } catch (LuaError &e) {
83
+ throw LuaError (std::string (e.what ()) + " . item=" + item.name );
84
+ }
85
+ }
76
86
lua_pop (L, 2 ); // Pop item and error handler
77
87
return true ;
78
88
}
@@ -95,8 +105,13 @@ bool ScriptApiItem::item_OnUse(ItemStack &item,
95
105
pushPointedThing (pointed);
96
106
if (lua_pcall (L, 3 , 1 , errorhandler))
97
107
scriptError ();
98
- if (!lua_isnil (L, -1 ))
99
- item = read_item (L,-1 , getServer ());
108
+ if (!lua_isnil (L, -1 )) {
109
+ try {
110
+ item = read_item (L,-1 , getServer ());
111
+ } catch (LuaError &e) {
112
+ throw LuaError (std::string (e.what ()) + " . item=" + item.name );
113
+ }
114
+ }
100
115
lua_pop (L, 2 ); // Pop item and error handler
101
116
return true ;
102
117
}
@@ -123,8 +138,13 @@ bool ScriptApiItem::item_OnCraft(ItemStack &item, ServerActiveObject *user,
123
138
InvRef::create (L, craft_inv);
124
139
if (lua_pcall (L, 4 , 1 , errorhandler))
125
140
scriptError ();
126
- if (!lua_isnil (L, -1 ))
127
- item = read_item (L,-1 , getServer ());
141
+ if (!lua_isnil (L, -1 )) {
142
+ try {
143
+ item = read_item (L,-1 , getServer ());
144
+ } catch (LuaError &e) {
145
+ throw LuaError (std::string (e.what ()) + " . item=" + item.name );
146
+ }
147
+ }
128
148
lua_pop (L, 2 ); // Pop item and error handler
129
149
return true ;
130
150
}
@@ -151,8 +171,13 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user,
151
171
InvRef::create (L, craft_inv);
152
172
if (lua_pcall (L, 4 , 1 , errorhandler))
153
173
scriptError ();
154
- if (!lua_isnil (L, -1 ))
155
- item = read_item (L,-1 , getServer ());
174
+ if (!lua_isnil (L, -1 )) {
175
+ try {
176
+ item = read_item (L,-1 , getServer ());
177
+ } catch (LuaError &e) {
178
+ throw LuaError (std::string (e.what ()) + " . item=" + item.name );
179
+ }
180
+ }
156
181
lua_pop (L, 2 ); // Pop item and error handler
157
182
return true ;
158
183
}
0 commit comments