mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 16:45:20 +02:00
Add more informative error messages for inventory and item method errors
This commit is contained in:
@@ -54,7 +54,7 @@ int ScriptApiDetached::detached_inventory_AllowMove(
|
|||||||
if(lua_pcall(L, 7, 1, errorhandler))
|
if(lua_pcall(L, 7, 1, errorhandler))
|
||||||
scriptError();
|
scriptError();
|
||||||
if(!lua_isnumber(L, -1))
|
if(!lua_isnumber(L, -1))
|
||||||
throw LuaError("allow_move should return a number");
|
throw LuaError("allow_move should return a number. name=" + name);
|
||||||
int ret = luaL_checkinteger(L, -1);
|
int ret = luaL_checkinteger(L, -1);
|
||||||
lua_pop(L, 2); // Pop integer and error handler
|
lua_pop(L, 2); // Pop integer and error handler
|
||||||
return ret;
|
return ret;
|
||||||
@@ -86,7 +86,7 @@ int ScriptApiDetached::detached_inventory_AllowPut(
|
|||||||
if(lua_pcall(L, 5, 1, errorhandler))
|
if(lua_pcall(L, 5, 1, errorhandler))
|
||||||
scriptError();
|
scriptError();
|
||||||
if(!lua_isnumber(L, -1))
|
if(!lua_isnumber(L, -1))
|
||||||
throw LuaError("allow_put should return a number");
|
throw LuaError("allow_put should return a number. name=" + name);
|
||||||
int ret = luaL_checkinteger(L, -1);
|
int ret = luaL_checkinteger(L, -1);
|
||||||
lua_pop(L, 2); // Pop integer and error handler
|
lua_pop(L, 2); // Pop integer and error handler
|
||||||
return ret;
|
return ret;
|
||||||
@@ -118,7 +118,7 @@ int ScriptApiDetached::detached_inventory_AllowTake(
|
|||||||
if(lua_pcall(L, 5, 1, errorhandler))
|
if(lua_pcall(L, 5, 1, errorhandler))
|
||||||
scriptError();
|
scriptError();
|
||||||
if(!lua_isnumber(L, -1))
|
if(!lua_isnumber(L, -1))
|
||||||
throw LuaError("allow_take should return a number");
|
throw LuaError("allow_take should return a number. name=" + name);
|
||||||
int ret = luaL_checkinteger(L, -1);
|
int ret = luaL_checkinteger(L, -1);
|
||||||
lua_pop(L, 2); // Pop integer and error handler
|
lua_pop(L, 2); // Pop integer and error handler
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -47,8 +47,13 @@ bool ScriptApiItem::item_OnDrop(ItemStack &item,
|
|||||||
pushFloatPos(L, pos);
|
pushFloatPos(L, pos);
|
||||||
if(lua_pcall(L, 3, 1, errorhandler))
|
if(lua_pcall(L, 3, 1, errorhandler))
|
||||||
scriptError();
|
scriptError();
|
||||||
if(!lua_isnil(L, -1))
|
if(!lua_isnil(L, -1)) {
|
||||||
|
try {
|
||||||
item = read_item(L,-1, getServer());
|
item = read_item(L,-1, getServer());
|
||||||
|
} catch (LuaError &e) {
|
||||||
|
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
lua_pop(L, 2); // Pop item and error handler
|
lua_pop(L, 2); // Pop item and error handler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -71,8 +76,13 @@ bool ScriptApiItem::item_OnPlace(ItemStack &item,
|
|||||||
pushPointedThing(pointed);
|
pushPointedThing(pointed);
|
||||||
if(lua_pcall(L, 3, 1, errorhandler))
|
if(lua_pcall(L, 3, 1, errorhandler))
|
||||||
scriptError();
|
scriptError();
|
||||||
if(!lua_isnil(L, -1))
|
if(!lua_isnil(L, -1)) {
|
||||||
|
try {
|
||||||
item = read_item(L,-1, getServer());
|
item = read_item(L,-1, getServer());
|
||||||
|
} catch (LuaError &e) {
|
||||||
|
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
lua_pop(L, 2); // Pop item and error handler
|
lua_pop(L, 2); // Pop item and error handler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -95,8 +105,13 @@ bool ScriptApiItem::item_OnUse(ItemStack &item,
|
|||||||
pushPointedThing(pointed);
|
pushPointedThing(pointed);
|
||||||
if(lua_pcall(L, 3, 1, errorhandler))
|
if(lua_pcall(L, 3, 1, errorhandler))
|
||||||
scriptError();
|
scriptError();
|
||||||
if(!lua_isnil(L, -1))
|
if(!lua_isnil(L, -1)) {
|
||||||
|
try {
|
||||||
item = read_item(L,-1, getServer());
|
item = read_item(L,-1, getServer());
|
||||||
|
} catch (LuaError &e) {
|
||||||
|
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
lua_pop(L, 2); // Pop item and error handler
|
lua_pop(L, 2); // Pop item and error handler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -123,8 +138,13 @@ bool ScriptApiItem::item_OnCraft(ItemStack &item, ServerActiveObject *user,
|
|||||||
InvRef::create(L, craft_inv);
|
InvRef::create(L, craft_inv);
|
||||||
if(lua_pcall(L, 4, 1, errorhandler))
|
if(lua_pcall(L, 4, 1, errorhandler))
|
||||||
scriptError();
|
scriptError();
|
||||||
if(!lua_isnil(L, -1))
|
if(!lua_isnil(L, -1)) {
|
||||||
|
try {
|
||||||
item = read_item(L,-1, getServer());
|
item = read_item(L,-1, getServer());
|
||||||
|
} catch (LuaError &e) {
|
||||||
|
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
lua_pop(L, 2); // Pop item and error handler
|
lua_pop(L, 2); // Pop item and error handler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -151,8 +171,13 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user,
|
|||||||
InvRef::create(L, craft_inv);
|
InvRef::create(L, craft_inv);
|
||||||
if(lua_pcall(L, 4, 1, errorhandler))
|
if(lua_pcall(L, 4, 1, errorhandler))
|
||||||
scriptError();
|
scriptError();
|
||||||
if(!lua_isnil(L, -1))
|
if(!lua_isnil(L, -1)) {
|
||||||
|
try {
|
||||||
item = read_item(L,-1, getServer());
|
item = read_item(L,-1, getServer());
|
||||||
|
} catch (LuaError &e) {
|
||||||
|
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
lua_pop(L, 2); // Pop item and error handler
|
lua_pop(L, 2); // Pop item and error handler
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user