3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
22 #include "lua_api/l_base.h"
23 #include "lua_api/l_metadata.h"
24 #include "irrlichttypes_bloated.h"
25 #include "nodemetadata.h"
27 class ServerEnvironment;
34 class NodeMetaRef : public MetaDataRef {
37 ServerEnvironment *m_env = nullptr;
38 Metadata *m_meta = nullptr;
39 bool m_is_local = false;
41 static const char className[];
42 static const luaL_Reg methodsServer[];
43 static const luaL_Reg methodsClient[];
45 static NodeMetaRef *checkobject(lua_State *L, int narg);
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.
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.
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.
60 virtual Metadata* getmeta(bool auto_create);
61 virtual void clearMeta();
63 virtual void reportMetadataChange();
65 virtual void handleToTable(lua_State *L, Metadata *_meta);
66 virtual bool handleFromTable(lua_State *L, int table, Metadata *_meta);
71 static int gc_object(lua_State *L);
73 // get_inventory(self)
74 static int l_get_inventory(lua_State *L);
76 // mark_as_private(self, <string> or {<string>, <string>, ...})
77 static int l_mark_as_private(lua_State *L);
80 NodeMetaRef(v3s16 p, ServerEnvironment *env);
81 NodeMetaRef(Metadata *meta);
83 ~NodeMetaRef() = default;
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);
89 // Client-sided version of the above
90 static void createClient(lua_State *L, Metadata *meta);
92 static void RegisterCommon(lua_State *L);
93 static void Register(lua_State *L);
94 static void RegisterClient(lua_State *L);