Skip to content

Commit ba8fa0b

Browse files
committedDec 18, 2013
Log guilty node name when allow_metadata_inventory_move/put/take fails
1 parent 1ed90c9 commit ba8fa0b

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed
 

Diff for: ‎src/script/cpp_api/s_nodemeta.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(v3s16 p,
4545
return 0;
4646

4747
// Push callback function on stack
48-
if(!getItemCallback(ndef->get(node).name.c_str(),
49-
"allow_metadata_inventory_move"))
48+
std::string nodename = ndef->get(node).name;
49+
if(!getItemCallback(nodename.c_str(), "allow_metadata_inventory_move"))
5050
return count;
5151

5252
// function(pos, from_list, from_index, to_list, to_index, count, player)
@@ -61,7 +61,8 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowMove(v3s16 p,
6161
scriptError();
6262
lua_remove(L, errorhandler); // Remove error handler
6363
if(!lua_isnumber(L, -1))
64-
throw LuaError(NULL, "allow_metadata_inventory_move should return a number");
64+
throw LuaError(NULL, "allow_metadata_inventory_move should"
65+
" return a number, guilty node: " + nodename);
6566
int num = luaL_checkinteger(L, -1);
6667
lua_pop(L, 1); // Pop integer
6768
return num;
@@ -85,8 +86,8 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(v3s16 p,
8586
return 0;
8687

8788
// Push callback function on stack
88-
if(!getItemCallback(ndef->get(node).name.c_str(),
89-
"allow_metadata_inventory_put"))
89+
std::string nodename = ndef->get(node).name;
90+
if(!getItemCallback(nodename.c_str(), "allow_metadata_inventory_put"))
9091
return stack.count;
9192

9293
// Call function(pos, listname, index, stack, player)
@@ -99,7 +100,8 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowPut(v3s16 p,
99100
scriptError();
100101
lua_remove(L, errorhandler); // Remove error handler
101102
if(!lua_isnumber(L, -1))
102-
throw LuaError(NULL, "allow_metadata_inventory_put should return a number");
103+
throw LuaError(NULL, "allow_metadata_inventory_put should"
104+
" return a number, guilty node: " + nodename);
103105
int num = luaL_checkinteger(L, -1);
104106
lua_pop(L, 1); // Pop integer
105107
return num;
@@ -123,8 +125,8 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(v3s16 p,
123125
return 0;
124126

125127
// Push callback function on stack
126-
if(!getItemCallback(ndef->get(node).name.c_str(),
127-
"allow_metadata_inventory_take"))
128+
std::string nodename = ndef->get(node).name;
129+
if(!getItemCallback(nodename.c_str(), "allow_metadata_inventory_take"))
128130
return stack.count;
129131

130132
// Call function(pos, listname, index, count, player)
@@ -137,7 +139,8 @@ int ScriptApiNodemeta::nodemeta_inventory_AllowTake(v3s16 p,
137139
scriptError();
138140
lua_remove(L, errorhandler); // Remove error handler
139141
if(!lua_isnumber(L, -1))
140-
throw LuaError(NULL, "allow_metadata_inventory_take should return a number");
142+
throw LuaError(NULL, "allow_metadata_inventory_take should"
143+
" return a number, guilty node: " + nodename);
141144
int num = luaL_checkinteger(L, -1);
142145
lua_pop(L, 1); // Pop integer
143146
return num;
@@ -162,8 +165,8 @@ void ScriptApiNodemeta::nodemeta_inventory_OnMove(v3s16 p,
162165
return;
163166

164167
// Push callback function on stack
165-
if(!getItemCallback(ndef->get(node).name.c_str(),
166-
"on_metadata_inventory_move"))
168+
std::string nodename = ndef->get(node).name;
169+
if(!getItemCallback(nodename.c_str(), "on_metadata_inventory_move"))
167170
return;
168171

169172
// function(pos, from_list, from_index, to_list, to_index, count, player)
@@ -197,8 +200,8 @@ void ScriptApiNodemeta::nodemeta_inventory_OnPut(v3s16 p,
197200
return;
198201

199202
// Push callback function on stack
200-
if(!getItemCallback(ndef->get(node).name.c_str(),
201-
"on_metadata_inventory_put"))
203+
std::string nodename = ndef->get(node).name;
204+
if(!getItemCallback(nodename.c_str(), "on_metadata_inventory_put"))
202205
return;
203206

204207
// Call function(pos, listname, index, stack, player)
@@ -230,8 +233,8 @@ void ScriptApiNodemeta::nodemeta_inventory_OnTake(v3s16 p,
230233
return;
231234

232235
// Push callback function on stack
233-
if(!getItemCallback(ndef->get(node).name.c_str(),
234-
"on_metadata_inventory_take"))
236+
std::string nodename = ndef->get(node).name;
237+
if(!getItemCallback(nodename.c_str(), "on_metadata_inventory_take"))
235238
return;
236239

237240
// Call function(pos, listname, index, stack, player)

0 commit comments

Comments
 (0)
Please sign in to comment.