aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_inventory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/script/cpp_api/s_inventory.cpp')
-rw-r--r--src/script/cpp_api/s_inventory.cpp84
1 files changed, 41 insertions, 43 deletions
diff --git a/src/script/cpp_api/s_inventory.cpp b/src/script/cpp_api/s_inventory.cpp
index e9c09f72e..e4d3f990d 100644
--- a/src/script/cpp_api/s_inventory.cpp
+++ b/src/script/cpp_api/s_inventory.cpp
@@ -26,8 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Return number of accepted items to be moved
int ScriptApiDetached::detached_inventory_AllowMove(
- const MoveAction &ma, int count,
- ServerActiveObject *player)
+ const MoveAction &ma, int count, ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
@@ -41,14 +40,15 @@ int ScriptApiDetached::detached_inventory_AllowMove(
// inv
InvRef::create(L, ma.from_inv);
lua_pushstring(L, ma.from_list.c_str()); // from_list
- lua_pushinteger(L, ma.from_i + 1); // from_index
- lua_pushstring(L, ma.to_list.c_str()); // to_list
- lua_pushinteger(L, ma.to_i + 1); // to_index
- lua_pushinteger(L, count); // count
- objectrefGetOrCreate(L, player); // player
+ lua_pushinteger(L, ma.from_i + 1); // from_index
+ lua_pushstring(L, ma.to_list.c_str()); // to_list
+ lua_pushinteger(L, ma.to_i + 1); // to_index
+ lua_pushinteger(L, count); // count
+ objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 7, 1, error_handler));
- if(!lua_isnumber(L, -1))
- throw LuaError("allow_move should return a number. name=" + ma.from_inv.name);
+ if (!lua_isnumber(L, -1))
+ throw LuaError("allow_move should return a number. name=" +
+ ma.from_inv.name);
int ret = luaL_checkinteger(L, -1);
lua_pop(L, 2); // Pop integer and error handler
return ret;
@@ -56,8 +56,7 @@ int ScriptApiDetached::detached_inventory_AllowMove(
// Return number of accepted items to be put
int ScriptApiDetached::detached_inventory_AllowPut(
- const MoveAction &ma, const ItemStack &stack,
- ServerActiveObject *player)
+ const MoveAction &ma, const ItemStack &stack, ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
@@ -68,14 +67,15 @@ int ScriptApiDetached::detached_inventory_AllowPut(
return stack.count; // All will be accepted
// Call function(inv, listname, index, stack, player)
- InvRef::create(L, ma.to_inv); // inv
+ InvRef::create(L, ma.to_inv); // inv
lua_pushstring(L, ma.to_list.c_str()); // listname
lua_pushinteger(L, ma.to_i + 1); // index
- LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(L, player); // player
+ LuaItemStack::create(L, stack); // stack
+ objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 5, 1, error_handler));
if (!lua_isnumber(L, -1))
- throw LuaError("allow_put should return a number. name=" + ma.to_inv.name);
+ throw LuaError("allow_put should return a number. name=" +
+ ma.to_inv.name);
int ret = luaL_checkinteger(L, -1);
lua_pop(L, 2); // Pop integer and error handler
return ret;
@@ -83,8 +83,7 @@ int ScriptApiDetached::detached_inventory_AllowPut(
// Return number of accepted items to be taken
int ScriptApiDetached::detached_inventory_AllowTake(
- const MoveAction &ma, const ItemStack &stack,
- ServerActiveObject *player)
+ const MoveAction &ma, const ItemStack &stack, ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
@@ -95,14 +94,15 @@ int ScriptApiDetached::detached_inventory_AllowTake(
return stack.count; // All will be accepted
// Call function(inv, listname, index, stack, player)
- InvRef::create(L, ma.from_inv); // inv
+ InvRef::create(L, ma.from_inv); // inv
lua_pushstring(L, ma.from_list.c_str()); // listname
- lua_pushinteger(L, ma.from_i + 1); // index
- LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(L, player); // player
+ lua_pushinteger(L, ma.from_i + 1); // index
+ LuaItemStack::create(L, stack); // stack
+ objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 5, 1, error_handler));
if (!lua_isnumber(L, -1))
- throw LuaError("allow_take should return a number. name=" + ma.from_inv.name);
+ throw LuaError("allow_take should return a number. name=" +
+ ma.from_inv.name);
int ret = luaL_checkinteger(L, -1);
lua_pop(L, 2); // Pop integer and error handler
return ret;
@@ -110,8 +110,7 @@ int ScriptApiDetached::detached_inventory_AllowTake(
// Report moved items
void ScriptApiDetached::detached_inventory_OnMove(
- const MoveAction &ma, int count,
- ServerActiveObject *player)
+ const MoveAction &ma, int count, ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
@@ -125,19 +124,18 @@ void ScriptApiDetached::detached_inventory_OnMove(
// inv
InvRef::create(L, ma.from_inv);
lua_pushstring(L, ma.from_list.c_str()); // from_list
- lua_pushinteger(L, ma.from_i + 1); // from_index
- lua_pushstring(L, ma.to_list.c_str()); // to_list
- lua_pushinteger(L, ma.to_i + 1); // to_index
- lua_pushinteger(L, count); // count
- objectrefGetOrCreate(L, player); // player
+ lua_pushinteger(L, ma.from_i + 1); // from_index
+ lua_pushstring(L, ma.to_list.c_str()); // to_list
+ lua_pushinteger(L, ma.to_i + 1); // to_index
+ lua_pushinteger(L, count); // count
+ objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 7, 0, error_handler));
- lua_pop(L, 1); // Pop error handler
+ lua_pop(L, 1); // Pop error handler
}
// Report put items
void ScriptApiDetached::detached_inventory_OnPut(
- const MoveAction &ma, const ItemStack &stack,
- ServerActiveObject *player)
+ const MoveAction &ma, const ItemStack &stack, ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
@@ -152,16 +150,15 @@ void ScriptApiDetached::detached_inventory_OnPut(
InvRef::create(L, ma.to_inv);
lua_pushstring(L, ma.to_list.c_str()); // listname
lua_pushinteger(L, ma.to_i + 1); // index
- LuaItemStack::create(L, stack); // stack
+ LuaItemStack::create(L, stack); // stack
objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 5, 0, error_handler));
- lua_pop(L, 1); // Pop error handler
+ lua_pop(L, 1); // Pop error handler
}
// Report taken items
void ScriptApiDetached::detached_inventory_OnTake(
- const MoveAction &ma, const ItemStack &stack,
- ServerActiveObject *player)
+ const MoveAction &ma, const ItemStack &stack, ServerActiveObject *player)
{
SCRIPTAPI_PRECHECKHEADER
@@ -175,11 +172,11 @@ void ScriptApiDetached::detached_inventory_OnTake(
// inv
InvRef::create(L, ma.from_inv);
lua_pushstring(L, ma.from_list.c_str()); // listname
- lua_pushinteger(L, ma.from_i + 1); // index
- LuaItemStack::create(L, stack); // stack
- objectrefGetOrCreate(L, player); // player
+ lua_pushinteger(L, ma.from_i + 1); // index
+ LuaItemStack::create(L, stack); // stack
+ objectrefGetOrCreate(L, player); // player
PCALL_RES(lua_pcall(L, 5, 0, error_handler));
- lua_pop(L, 1); // Pop error handler
+ lua_pop(L, 1); // Pop error handler
}
// Retrieves core.detached_inventories[name][callbackname]
@@ -199,7 +196,8 @@ bool ScriptApiDetached::getDetachedInventoryCallback(
lua_remove(L, -2);
// Should be a table
if (lua_type(L, -1) != LUA_TTABLE) {
- errorstream<<"Detached inventory \""<<name<<"\" not defined"<<std::endl;
+ errorstream << "Detached inventory \"" << name << "\" not defined"
+ << std::endl;
lua_pop(L, 1);
return false;
}
@@ -218,8 +216,8 @@ bool ScriptApiDetached::getDetachedInventoryCallback(
return false;
}
- errorstream << "Detached inventory \"" << name << "\" callback \""
- << callbackname << "\" is not a function" << std::endl;
+ errorstream << "Detached inventory \"" << name << "\" callback \"" << callbackname
+ << "\" is not a function" << std::endl;
lua_pop(L, 1);
return false;
}