Luanti 5.15.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
12
13/*
14 InvRef
15*/
16
17class InvRef : public ModApiBase {
18private:
20
21 static const luaL_Reg methods[];
22
23 static Inventory* getinv(lua_State *L, InvRef *ref);
24
25 static InventoryList* getlist(lua_State *L, InvRef *ref,
26 const char *listname);
27
28 static void reportInventoryChange(lua_State *L, InvRef *ref);
29
30 // Exported functions
31
32 // garbage collector
33 static int gc_object(lua_State *L);
34
35 // is_empty(self, listname) -> true/false
36 static int l_is_empty(lua_State *L);
37
38 // get_size(self, listname)
39 static int l_get_size(lua_State *L);
40
41 // get_width(self, listname)
42 static int l_get_width(lua_State *L);
43
44 // set_size(self, listname, size)
45 static int l_set_size(lua_State *L);
46
47 // set_width(self, listname, size)
48 static int l_set_width(lua_State *L);
49
50 // get_stack(self, listname, i) -> itemstack
51 static int l_get_stack(lua_State *L);
52
53 // set_stack(self, listname, i, stack) -> true/false
54 static int l_set_stack(lua_State *L);
55
56 // get_list(self, listname) -> list or nil
57 static int l_get_list(lua_State *L);
58
59 // set_list(self, listname, list)
60 static int l_set_list(lua_State *L);
61
62 // get_lists(self) -> list of InventoryLists
63 static int l_get_lists(lua_State *L);
64
65 // set_lists(self, lists)
66 static int l_set_lists(lua_State *L);
67
68 // add_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
69 // Returns the leftover stack
70 static int l_add_item(lua_State *L);
71
72 // room_for_item(self, listname, itemstack or itemstring or table or nil) -> true/false
73 // Returns true if the item completely fits into the list
74 static int l_room_for_item(lua_State *L);
75
76 // contains_item(self, listname, itemstack or itemstring or table or nil, [match_meta]) -> true/false
77 // Returns true if the list contains the given count of the given item name
78 static int l_contains_item(lua_State *L);
79
80 // remove_item(self, listname, itemstack or itemstring or table or nil) -> itemstack
81 // Returns the items that were actually removed
82 static int l_remove_item(lua_State *L);
83
84 // get_location() -> location (like get_inventory(location))
85 static int l_get_location(lua_State *L);
86
87public:
88 InvRef(const InventoryLocation &loc);
89
90 ~InvRef() = default;
91
92 // Creates an InvRef and leaves it on top of stack
93 // Not callable from Lua; all references are created on the C side.
94 static void create(lua_State *L, const InventoryLocation &loc);
95 static void Register(lua_State *L);
96
97 static const char className[];
98};
99
101private:
102 static int l_create_detached_inventory_raw(lua_State *L);
103
104 static int l_remove_detached_inventory_raw(lua_State *L);
105
106 static int l_get_inventory(lua_State *L);
107
108public:
109 static void Initialize(lua_State *L, int top);
110};
Definition l_inventory.h:17
static int l_set_list(lua_State *L)
Definition l_inventory.cpp:215
static const char className[]
Definition l_inventory.h:97
static void reportInventoryChange(lua_State *L, InvRef *ref)
Definition l_inventory.cpp:31
InventoryLocation m_loc
Definition l_inventory.h:19
static int l_remove_item(lua_State *L)
Definition l_inventory.cpp:331
static int l_add_item(lua_State *L)
Definition l_inventory.cpp:276
static int l_room_for_item(lua_State *L)
Definition l_inventory.cpp:296
static int l_get_lists(lua_State *L)
Definition l_inventory.cpp:235
static const luaL_Reg methods[]
Definition l_inventory.h:418
static int l_set_size(lua_State *L)
Definition l_inventory.cpp:92
static int l_set_stack(lua_State *L)
Definition l_inventory.cpp:176
static int l_get_list(lua_State *L)
Definition l_inventory.cpp:195
static int gc_object(lua_State *L)
Definition l_inventory.cpp:40
static int l_get_width(lua_State *L)
Definition l_inventory.cpp:77
static int l_set_width(lua_State *L)
Definition l_inventory.cpp:131
~InvRef()=default
static int l_get_stack(lua_State *L)
Definition l_inventory.cpp:161
InvRef(const InventoryLocation &loc)
Definition l_inventory.cpp:389
static Inventory * getinv(lua_State *L, InvRef *ref)
Definition l_inventory.cpp:16
static int l_is_empty(lua_State *L)
Definition l_inventory.cpp:47
static int l_get_location(lua_State *L)
Definition l_inventory.cpp:351
static void create(lua_State *L, const InventoryLocation &loc)
Definition l_inventory.cpp:396
static int l_contains_item(lua_State *L)
Definition l_inventory.cpp:313
static InventoryList * getlist(lua_State *L, InvRef *ref, const char *listname)
Definition l_inventory.cpp:21
static int l_set_lists(lua_State *L)
Definition l_inventory.cpp:248
static int l_get_size(lua_State *L)
Definition l_inventory.cpp:62
Definition inventory.h:157
Definition inventory.h:277
Definition l_base.h:27
Definition l_inventory.h:100
static int l_remove_detached_inventory_raw(lua_State *L)
Definition l_inventory.cpp:497
static int l_create_detached_inventory_raw(lua_State *L)
Definition l_inventory.cpp:481
static void Initialize(lua_State *L, int top)
Definition l_inventory.cpp:505
static int l_get_inventory(lua_State *L)
Definition l_inventory.cpp:439
Definition inventorymanager.h:18