Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
l_inventory.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5#pragma once
6
7#include "lua_api/l_base.h"
8
9#include "inventory.h"
10#include "inventorymanager.h"
11
12class RemotePlayer;
13
14/*
15 InvRef
16*/
17
18class InvRef : public ModApiBase {
19private:
21
22 static const luaL_Reg methods[];
23
24 static Inventory* getinv(lua_State *L, InvRef *ref);
25
26 static InventoryList* getlist(lua_State *L, InvRef *ref,
27 const char *listname);
28
29 static void reportInventoryChange(lua_State *L, InvRef *ref);
30
31 // Exported functions
32
33 // garbage collector
34 static int gc_object(lua_State *L);
35
36 // is_empty(self, listname) -> true/false
37 static int l_is_empty(lua_State *L);
38
39 // get_size(self, listname)
40 static int l_get_size(lua_State *L);
41
42 // get_width(self, listname)
43 static int l_get_width(lua_State *L);
44
45 // set_size(self, listname, size)
46 static int l_set_size(lua_State *L);
47
48 // set_width(self, listname, size)
49 static int l_set_width(lua_State *L);
50
51 // get_stack(self, listname, i) -> itemstack
52 static int l_get_stack(lua_State *L);
53
54 // set_stack(self, listname, i, stack) -> true/false
55 static int l_set_stack(lua_State *L);
56
57 // get_list(self, listname) -> list or nil
58 static int l_get_list(lua_State *L);
59
60 // set_list(self, listname, list)
61 static int l_set_list(lua_State *L);
62
63 // get_lists(self) -> list of InventoryLists
64 static int l_get_lists(lua_State *L);
65
66 // set_lists(self, lists)
67 static int l_set_lists(lua_State *L);
68
69 // add_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
70 // Returns the leftover stack
71 static int l_add_item(lua_State *L);
72
73 // room_for_item(self, listname, itemstack or itemstring or table or nil) -> true/false
74 // Returns true if the item completely fits into the list
75 static int l_room_for_item(lua_State *L);
76
77 // contains_item(self, listname, itemstack or itemstring or table or nil, [match_meta]) -> true/false
78 // Returns true if the list contains the given count of the given item name
79 static int l_contains_item(lua_State *L);
80
81 // remove_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
82 // Returns the items that were actually removed
83 static int l_remove_item(lua_State *L);
84
85 // get_location() -> location (like get_inventory(location))
86 static int l_get_location(lua_State *L);
87
88public:
89 InvRef(const InventoryLocation &loc);
90
91 ~InvRef() = default;
92
93 // Creates an InvRef and leaves it on top of stack
94 // Not callable from Lua; all references are created on the C side.
95 static void create(lua_State *L, const InventoryLocation &loc);
96 static void Register(lua_State *L);
97
98 static const char className[];
99};
100
102private:
103 static int l_create_detached_inventory_raw(lua_State *L);
104
105 static int l_remove_detached_inventory_raw(lua_State *L);
106
107 static int l_get_inventory(lua_State *L);
108
109public:
110 static void Initialize(lua_State *L, int top);
111};
Definition l_inventory.h:18
static int l_set_list(lua_State *L)
Definition l_inventory.cpp:218
static const char className[]
Definition l_inventory.h:98
static void reportInventoryChange(lua_State *L, InvRef *ref)
Definition l_inventory.cpp:33
InventoryLocation m_loc
Definition l_inventory.h:20
static int l_remove_item(lua_State *L)
Definition l_inventory.cpp:336
static int l_add_item(lua_State *L)
Definition l_inventory.cpp:279
static int l_room_for_item(lua_State *L)
Definition l_inventory.cpp:299
static int l_get_lists(lua_State *L)
Definition l_inventory.cpp:238
static const luaL_Reg methods[]
Definition l_inventory.h:422
static int l_set_size(lua_State *L)
Definition l_inventory.cpp:94
static int l_set_stack(lua_State *L)
Definition l_inventory.cpp:179
static int l_get_list(lua_State *L)
Definition l_inventory.cpp:198
static int gc_object(lua_State *L)
Definition l_inventory.cpp:42
static int l_get_width(lua_State *L)
Definition l_inventory.cpp:79
static int l_set_width(lua_State *L)
Definition l_inventory.cpp:134
~InvRef()=default
static int l_get_stack(lua_State *L)
Definition l_inventory.cpp:164
InvRef(const InventoryLocation &loc)
Definition l_inventory.cpp:393
static Inventory * getinv(lua_State *L, InvRef *ref)
Definition l_inventory.cpp:18
static int l_is_empty(lua_State *L)
Definition l_inventory.cpp:49
static int l_get_location(lua_State *L)
Definition l_inventory.cpp:355
static void create(lua_State *L, const InventoryLocation &loc)
Definition l_inventory.cpp:400
static int l_contains_item(lua_State *L)
Definition l_inventory.cpp:316
static InventoryList * getlist(lua_State *L, InvRef *ref, const char *listname)
Definition l_inventory.cpp:23
static int l_set_lists(lua_State *L)
Definition l_inventory.cpp:251
static int l_get_size(lua_State *L)
Definition l_inventory.cpp:64
Definition inventory.h:194
Definition inventory.h:314
Definition l_base.h:28
Definition l_inventory.h:101
static int l_remove_detached_inventory_raw(lua_State *L)
Definition l_inventory.cpp:501
static int l_create_detached_inventory_raw(lua_State *L)
Definition l_inventory.cpp:485
static void Initialize(lua_State *L, int top)
Definition l_inventory.cpp:509
static int l_get_inventory(lua_State *L)
Definition l_inventory.cpp:443
Definition remoteplayer.h:26
Definition inventorymanager.h:18