/*MinetestCopyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>This program is free software; you can redistribute it and/or modifyit under the terms of the GNU Lesser General Public License as published bythe Free Software Foundation; either version 2.1 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU Lesser General Public License for more details.You should have received a copy of the GNU Lesser General Public License alongwith this program; if not, write to the Free Software Foundation, Inc.,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.*/#ifndef L_INVENTORY_H_#define L_INVENTORY_H_#include"lua_api/l_base.h"#include"inventory.h"#include"inventorymanager.h"class Player;/* InvRef*/class InvRef :public ModApiBase {private:
InventoryLocation m_loc;static const char className[];static const luaL_reg methods[];static InvRef *checkobject(lua_State *L,int narg);static Inventory*getinv(lua_State *L, InvRef *ref);static InventoryList*getlist(lua_State *L, InvRef *ref,const char*listname);static voidreportInventoryChange(lua_State *L, InvRef *ref);// Exported functions// garbage collectorstatic intgc_object(lua_State *L);// is_empty(self, listname) -> true/falsestatic intl_is_empty(lua_State *L);// get_size(self, listname)static intl_get_size(lua_State *L);// get_width(self, listname)static intl_get_width(lua_State *L);// set_size(self, listname, size)static intl_set_size(lua_State *L);// set_width(self, listname, size)static intl_set_width(lua_State *L);// get_stack(self, listname, i) -> itemstackstatic intl_get_stack(lua_State *L);// set_stack(self, listname, i, stack) -> true/falsestatic intl_set_stack(lua_State *L);// get_list(self, listname) -> list or nilstatic intl_get_list(lua_State *L);// set_list(self, listname, list)static intl_set_list(lua_State *L);// add_item(self, listname, itemstack or itemstring or table or nil) -> itemstack// Returns the leftover stackstatic intl_add_item(lua_State *L);// room_for_item(self, listname, itemstack or itemstring or table or nil) -> true/false// Returns true if the item completely fits into the liststatic intl_room_for_item(lua_State *L);// contains_item(self, listname, itemstack or itemstring or table or nil) -> true/false// Returns true if the list contains the given count of the given item namestatic intl_contains_item(lua_State *L);// remove_item(self, listname, itemstack or itemstring or table or nil) -> itemstack// Returns the items that were actually removedstatic intl_remove_item(lua_State *L);// get_location() -> location (like minetest.get_inventory(location))static intl_get_location(lua_State *L);public:InvRef(const InventoryLocation &loc);~InvRef();// Creates an InvRef and leaves it on top of stack// Not callable from Lua; all references are created on the C side.static voidcreate(lua_State *L,const InventoryLocation &loc);static voidcreatePlayer(lua_State *L, Player *player);static voidcreateNodeMeta(lua_State *L, v3s16 p);static voidRegister(lua_State *L);};class ModApiInventory :public ModApiBase {private:static intl_create_detached_inventory_raw(lua_State *L);static intl_get_inventory(lua_State *L);static voidinventory_set_list_from_lua(Inventory *inv,const char*name,
lua_State *L,int tableindex,int forcesize);static voidinventory_get_list_to_lua(Inventory *inv,const char*name,
lua_State *L);public:static voidInitialize(lua_State *L,int top);};#endif/* L_INVENTORY_H_ */