]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_inventory.h
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.git] / src / script / lua_api / l_inventory.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef L_INVENTORY_H_
21 #define L_INVENTORY_H_
22
23 #include "lua_api/l_base.h"
24
25 #include "inventory.h"
26 #include "inventorymanager.h"
27
28 class Player;
29
30 /*
31         InvRef
32 */
33
34 class InvRef : public ModApiBase {
35 private:
36         InventoryLocation m_loc;
37
38         static const char className[];
39         static const luaL_reg methods[];
40
41         static InvRef *checkobject(lua_State *L, int narg);
42
43         static Inventory* getinv(lua_State *L, InvRef *ref);
44
45         static InventoryList* getlist(lua_State *L, InvRef *ref,
46                         const char *listname);
47
48         static void reportInventoryChange(lua_State *L, InvRef *ref);
49
50         // Exported functions
51
52         // garbage collector
53         static int gc_object(lua_State *L);
54
55         // is_empty(self, listname) -> true/false
56         static int l_is_empty(lua_State *L);
57
58         // get_size(self, listname)
59         static int l_get_size(lua_State *L);
60
61         // get_width(self, listname)
62         static int l_get_width(lua_State *L);
63
64         // set_size(self, listname, size)
65         static int l_set_size(lua_State *L);
66
67         // set_width(self, listname, size)
68         static int l_set_width(lua_State *L);
69
70         // get_stack(self, listname, i) -> itemstack
71         static int l_get_stack(lua_State *L);
72
73         // set_stack(self, listname, i, stack) -> true/false
74         static int l_set_stack(lua_State *L);
75
76         // get_list(self, listname) -> list or nil
77         static int l_get_list(lua_State *L);
78
79         // set_list(self, listname, list)
80         static int l_set_list(lua_State *L);
81
82         // add_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
83         // Returns the leftover stack
84         static int l_add_item(lua_State *L);
85
86         // room_for_item(self, listname, itemstack or itemstring or table or nil) -> true/false
87         // Returns true if the item completely fits into the list
88         static int l_room_for_item(lua_State *L);
89
90         // contains_item(self, listname, itemstack or itemstring or table or nil) -> true/false
91         // Returns true if the list contains the given count of the given item name
92         static int l_contains_item(lua_State *L);
93
94         // remove_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
95         // Returns the items that were actually removed
96         static int l_remove_item(lua_State *L);
97
98         // get_location() -> location (like minetest.get_inventory(location))
99         static int l_get_location(lua_State *L);
100
101 public:
102         InvRef(const InventoryLocation &loc);
103
104         ~InvRef();
105
106         // Creates an InvRef and leaves it on top of stack
107         // Not callable from Lua; all references are created on the C side.
108         static void create(lua_State *L, const InventoryLocation &loc);
109         static void createPlayer(lua_State *L, Player *player);
110         static void createNodeMeta(lua_State *L, v3s16 p);
111         static void Register(lua_State *L);
112 };
113
114 class ModApiInventory : public ModApiBase {
115 private:
116         static int l_create_detached_inventory_raw(lua_State *L);
117
118         static int l_get_inventory(lua_State *L);
119
120         static void inventory_set_list_from_lua(Inventory *inv, const char *name,
121                         lua_State *L, int tableindex, int forcesize);
122         static void inventory_get_list_to_lua(Inventory *inv, const char *name,
123                         lua_State *L);
124
125 public:
126         static void Initialize(lua_State *L, int top);
127 };
128
129 #endif /* L_INVENTORY_H_ */