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