mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add more informative error messages for inventory and item method errors
This commit is contained in:
parent
31fe72dbac
commit
f3d83a4516
2 changed files with 38 additions and 13 deletions
|
@ -47,8 +47,13 @@ bool ScriptApiItem::item_OnDrop(ItemStack &item,
|
|||
pushFloatPos(L, pos);
|
||||
if(lua_pcall(L, 3, 1, errorhandler))
|
||||
scriptError();
|
||||
if(!lua_isnil(L, -1))
|
||||
item = read_item(L,-1, getServer());
|
||||
if(!lua_isnil(L, -1)) {
|
||||
try {
|
||||
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
|
||||
return true;
|
||||
}
|
||||
|
@ -71,8 +76,13 @@ bool ScriptApiItem::item_OnPlace(ItemStack &item,
|
|||
pushPointedThing(pointed);
|
||||
if(lua_pcall(L, 3, 1, errorhandler))
|
||||
scriptError();
|
||||
if(!lua_isnil(L, -1))
|
||||
item = read_item(L,-1, getServer());
|
||||
if(!lua_isnil(L, -1)) {
|
||||
try {
|
||||
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
|
||||
return true;
|
||||
}
|
||||
|
@ -95,8 +105,13 @@ bool ScriptApiItem::item_OnUse(ItemStack &item,
|
|||
pushPointedThing(pointed);
|
||||
if(lua_pcall(L, 3, 1, errorhandler))
|
||||
scriptError();
|
||||
if(!lua_isnil(L, -1))
|
||||
item = read_item(L,-1, getServer());
|
||||
if(!lua_isnil(L, -1)) {
|
||||
try {
|
||||
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
|
||||
return true;
|
||||
}
|
||||
|
@ -123,8 +138,13 @@ bool ScriptApiItem::item_OnCraft(ItemStack &item, ServerActiveObject *user,
|
|||
InvRef::create(L, craft_inv);
|
||||
if(lua_pcall(L, 4, 1, errorhandler))
|
||||
scriptError();
|
||||
if(!lua_isnil(L, -1))
|
||||
item = read_item(L,-1, getServer());
|
||||
if(!lua_isnil(L, -1)) {
|
||||
try {
|
||||
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
|
||||
return true;
|
||||
}
|
||||
|
@ -151,8 +171,13 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user,
|
|||
InvRef::create(L, craft_inv);
|
||||
if(lua_pcall(L, 4, 1, errorhandler))
|
||||
scriptError();
|
||||
if(!lua_isnil(L, -1))
|
||||
item = read_item(L,-1, getServer());
|
||||
if(!lua_isnil(L, -1)) {
|
||||
try {
|
||||
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
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue