]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_nodemeta.h
Async-related script cleanups
[dragonfireclient.git] / src / script / lua_api / l_nodemeta.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 #pragma once
21
22 #include "lua_api/l_base.h"
23 #include "lua_api/l_metadata.h"
24 #include "irrlichttypes_bloated.h"
25 #include "nodemetadata.h"
26
27 class ServerEnvironment;
28 class NodeMetadata;
29
30 /*
31         NodeMetaRef
32 */
33
34 class NodeMetaRef : public MetaDataRef {
35 private:
36         v3s16 m_p;
37         ServerEnvironment *m_env = nullptr;
38         Metadata *m_meta = nullptr;
39         bool m_is_local = false;
40
41         static const char className[];
42         static const luaL_Reg methodsServer[];
43         static const luaL_Reg methodsClient[];
44
45         static NodeMetaRef *checkobject(lua_State *L, int narg);
46
47         /**
48          * Retrieve metadata for a node.
49          * If @p auto_create is set and the specified node has no metadata information
50          * associated with it yet, the method attempts to attach a new metadata object
51          * to the node and returns a pointer to the metadata when successful.
52          *
53          * However, it is NOT guaranteed that the method will return a pointer,
54          * and @c NULL may be returned in case of an error regardless of @p auto_create.
55          *
56          * @param ref specifies the node for which the associated metadata is retrieved.
57          * @param auto_create when true, try to create metadata information for the node if it has none.
58          * @return pointer to a @c NodeMetadata object or @c NULL in case of error.
59          */
60         virtual Metadata* getmeta(bool auto_create);
61         virtual void clearMeta();
62
63         virtual void reportMetadataChange(const std::string *name = nullptr);
64
65         virtual void handleToTable(lua_State *L, Metadata *_meta);
66         virtual bool handleFromTable(lua_State *L, int table, Metadata *_meta);
67
68         // Exported functions
69
70         // garbage collector
71         static int gc_object(lua_State *L);
72
73         // get_inventory(self)
74         static int l_get_inventory(lua_State *L);
75
76         // mark_as_private(self, <string> or {<string>, <string>, ...})
77         static int l_mark_as_private(lua_State *L);
78
79 public:
80         NodeMetaRef(v3s16 p, ServerEnvironment *env);
81         NodeMetaRef(Metadata *meta);
82
83         ~NodeMetaRef() = default;
84
85         // Creates an NodeMetaRef and leaves it on top of stack
86         // Not callable from Lua; all references are created on the C side.
87         static void create(lua_State *L, v3s16 p, ServerEnvironment *env);
88
89         // Client-sided version of the above
90         static void createClient(lua_State *L, Metadata *meta);
91
92         static void RegisterCommon(lua_State *L);
93         static void Register(lua_State *L);
94         static void RegisterClient(lua_State *L);
95 };