aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-03-15 17:20:52 -0400
committerShadowNinja <shadowninja@minetest.net>2014-03-15 17:20:52 -0400
commitf3d83a4516eb9c6658a7c3e07bf1b7d4f4996bef (patch)
tree3bd25ee5e996abae53e55671919a2fee7fa8f6d6 /src/script/cpp_api
parent31fe72dbac3d53e8da21ef116ccf99febbc5196e (diff)
downloadminetest-f3d83a4516eb9c6658a7c3e07bf1b7d4f4996bef.tar.gz
minetest-f3d83a4516eb9c6658a7c3e07bf1b7d4f4996bef.tar.bz2
minetest-f3d83a4516eb9c6658a7c3e07bf1b7d4f4996bef.zip
Add more informative error messages for inventory and item method errors
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r--src/script/cpp_api/s_inventory.cpp6
-rw-r--r--src/script/cpp_api/s_item.cpp45
2 files changed, 38 insertions, 13 deletions
diff --git a/src/script/cpp_api/s_inventory.cpp b/src/script/cpp_api/s_inventory.cpp
index 835c0818f..dd7e26510 100644
--- a/src/script/cpp_api/s_inventory.cpp
+++ b/src/script/cpp_api/s_inventory.cpp
@@ -54,7 +54,7 @@ int ScriptApiDetached::detached_inventory_AllowMove(
if(lua_pcall(L, 7, 1, errorhandler))
scriptError();
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);
lua_pop(L, 2); // Pop integer and error handler
return ret;
@@ -86,7 +86,7 @@ int ScriptApiDetached::detached_inventory_AllowPut(
if(lua_pcall(L, 5, 1, errorhandler))
scriptError();
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);
lua_pop(L, 2); // Pop integer and error handler
return ret;
@@ -118,7 +118,7 @@ int ScriptApiDetached::detached_inventory_AllowTake(
if(lua_pcall(L, 5, 1, errorhandler))
scriptError();
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);
lua_pop(L, 2); // Pop integer and error handler
return ret;
diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp
index 49729e57b..41413d61c 100644
--- a/src/script/cpp_api/s_item.cpp
+++ b/src/script/cpp_api/s_item.cpp
@@ -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;
}