summaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_inventory.cpp
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-04-15 13:30:46 -0400
committerShadowNinja <shadowninja@minetest.net>2014-04-27 16:15:53 -0400
commitdb4ea4658c58772ee447ff0eff8bb39b692081ec (patch)
tree0ef394ea43e667bff1660bb576fe4f9013ce404b /src/script/cpp_api/s_inventory.cpp
parent1838a3fd696782b1733a435bbb25accf3e40d1f3 (diff)
downloadminetest-db4ea4658c58772ee447ff0eff8bb39b692081ec.tar.gz
minetest-db4ea4658c58772ee447ff0eff8bb39b692081ec.tar.bz2
minetest-db4ea4658c58772ee447ff0eff8bb39b692081ec.zip
Only push the Lua error handler once
Diffstat (limited to 'src/script/cpp_api/s_inventory.cpp')
-rw-r--r--src/script/cpp_api/s_inventory.cpp55
1 files changed, 17 insertions, 38 deletions
diff --git a/src/script/cpp_api/s_inventory.cpp b/src/script/cpp_api/s_inventory.cpp
index dd7e26510..a2d186d00 100644
--- a/src/script/cpp_api/s_inventory.cpp
+++ b/src/script/cpp_api/s_inventory.cpp
@@ -33,11 +33,8 @@ int ScriptApiDetached::detached_inventory_AllowMove(
{
SCRIPTAPI_PRECHECKHEADER
- lua_pushcfunction(L, script_error_handler);
- int errorhandler = lua_gettop(L);
-
// Push callback function on stack
- if(!getDetachedInventoryCallback(name, "allow_move"))
+ if (!getDetachedInventoryCallback(name, "allow_move"))
return count;
// function(inv, from_list, from_index, to_list, to_index, count, player)
@@ -51,12 +48,12 @@ int ScriptApiDetached::detached_inventory_AllowMove(
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
objectrefGetOrCreate(player); // player
- if(lua_pcall(L, 7, 1, errorhandler))
+ if (lua_pcall(L, 7, 1, m_errorhandler))
scriptError();
if(!lua_isnumber(L, -1))
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
+ lua_pop(L, 1); // Pop integer
return ret;
}
@@ -68,11 +65,8 @@ int ScriptApiDetached::detached_inventory_AllowPut(
{
SCRIPTAPI_PRECHECKHEADER
- lua_pushcfunction(L, script_error_handler);
- int errorhandler = lua_gettop(L);
-
// Push callback function on stack
- if(!getDetachedInventoryCallback(name, "allow_put"))
+ if (!getDetachedInventoryCallback(name, "allow_put"))
return stack.count; // All will be accepted
// Call function(inv, listname, index, stack, player)
@@ -83,12 +77,12 @@ int ScriptApiDetached::detached_inventory_AllowPut(
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(player); // player
- if(lua_pcall(L, 5, 1, errorhandler))
+ if (lua_pcall(L, 5, 1, m_errorhandler))
scriptError();
- if(!lua_isnumber(L, -1))
+ if (!lua_isnumber(L, -1))
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
+ lua_pop(L, 1); // Pop integer
return ret;
}
@@ -100,11 +94,8 @@ int ScriptApiDetached::detached_inventory_AllowTake(
{
SCRIPTAPI_PRECHECKHEADER
- lua_pushcfunction(L, script_error_handler);
- int errorhandler = lua_gettop(L);
-
// Push callback function on stack
- if(!getDetachedInventoryCallback(name, "allow_take"))
+ if (!getDetachedInventoryCallback(name, "allow_take"))
return stack.count; // All will be accepted
// Call function(inv, listname, index, stack, player)
@@ -115,12 +106,12 @@ int ScriptApiDetached::detached_inventory_AllowTake(
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(player); // player
- if(lua_pcall(L, 5, 1, errorhandler))
+ if (lua_pcall(L, 5, 1, m_errorhandler))
scriptError();
- if(!lua_isnumber(L, -1))
+ if (!lua_isnumber(L, -1))
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
+ lua_pop(L, 1); // Pop integer
return ret;
}
@@ -133,11 +124,8 @@ void ScriptApiDetached::detached_inventory_OnMove(
{
SCRIPTAPI_PRECHECKHEADER
- lua_pushcfunction(L, script_error_handler);
- int errorhandler = lua_gettop(L);
-
// Push callback function on stack
- if(!getDetachedInventoryCallback(name, "on_move"))
+ if (!getDetachedInventoryCallback(name, "on_move"))
return;
// function(inv, from_list, from_index, to_list, to_index, count, player)
@@ -151,9 +139,8 @@ void ScriptApiDetached::detached_inventory_OnMove(
lua_pushinteger(L, to_index + 1); // to_index
lua_pushinteger(L, count); // count
objectrefGetOrCreate(player); // player
- if(lua_pcall(L, 7, 0, errorhandler))
+ if (lua_pcall(L, 7, 0, m_errorhandler))
scriptError();
- lua_pop(L, 1); // Pop error handler
}
// Report put items
@@ -164,11 +151,8 @@ void ScriptApiDetached::detached_inventory_OnPut(
{
SCRIPTAPI_PRECHECKHEADER
- lua_pushcfunction(L, script_error_handler);
- int errorhandler = lua_gettop(L);
-
// Push callback function on stack
- if(!getDetachedInventoryCallback(name, "on_put"))
+ if (!getDetachedInventoryCallback(name, "on_put"))
return;
// Call function(inv, listname, index, stack, player)
@@ -180,9 +164,8 @@ void ScriptApiDetached::detached_inventory_OnPut(
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(player); // player
- if(lua_pcall(L, 5, 0, errorhandler))
+ if (lua_pcall(L, 5, 0, m_errorhandler))
scriptError();
- lua_pop(L, 1); // Pop error handler
}
// Report taken items
@@ -193,11 +176,8 @@ void ScriptApiDetached::detached_inventory_OnTake(
{
SCRIPTAPI_PRECHECKHEADER
- lua_pushcfunction(L, script_error_handler);
- int errorhandler = lua_gettop(L);
-
// Push callback function on stack
- if(!getDetachedInventoryCallback(name, "on_take"))
+ if (!getDetachedInventoryCallback(name, "on_take"))
return;
// Call function(inv, listname, index, stack, player)
@@ -209,9 +189,8 @@ void ScriptApiDetached::detached_inventory_OnTake(
lua_pushinteger(L, index + 1); // index
LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(player); // player
- if(lua_pcall(L, 5, 0, errorhandler))
+ if (lua_pcall(L, 5, 0, m_errorhandler))
scriptError();
- lua_pop(L, 1); // Pop error handler
}
// Retrieves minetest.detached_inventories[name][callbackname]