Clean up/improve some scriptapi error handling code
This commit is contained in:
@@ -29,6 +29,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "inventory.h"
|
||||
#include "inventorymanager.h"
|
||||
|
||||
#define WRAP_LUAERROR(e, detail) \
|
||||
LuaError(std::string(__FUNCTION__) + ": " + (e).what() + ". " detail)
|
||||
|
||||
bool ScriptApiItem::item_OnDrop(ItemStack &item,
|
||||
ServerActiveObject *dropper, v3f pos)
|
||||
{
|
||||
@@ -49,7 +52,7 @@ bool ScriptApiItem::item_OnDrop(ItemStack &item,
|
||||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
@@ -81,7 +84,7 @@ bool ScriptApiItem::item_OnPlace(ItemStack &item,
|
||||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
@@ -108,7 +111,7 @@ bool ScriptApiItem::item_OnUse(ItemStack &item,
|
||||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
@@ -133,7 +136,7 @@ bool ScriptApiItem::item_OnSecondaryUse(ItemStack &item,
|
||||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
@@ -165,7 +168,7 @@ bool ScriptApiItem::item_OnCraft(ItemStack &item, ServerActiveObject *user,
|
||||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
@@ -197,7 +200,7 @@ bool ScriptApiItem::item_CraftPredict(ItemStack &item, ServerActiveObject *user,
|
||||
try {
|
||||
item = read_item(L, -1, getServer()->idef());
|
||||
} catch (LuaError &e) {
|
||||
throw LuaError(std::string(e.what()) + ". item=" + item.name);
|
||||
throw WRAP_LUAERROR(e, "item=" + item.name);
|
||||
}
|
||||
}
|
||||
lua_pop(L, 2); // Pop item and error handler
|
||||
|
||||
Reference in New Issue
Block a user