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