]> git.lizzy.rs Git - minetest.git/blob - src/script/lua_api/l_nodemeta.h
Rename macros with two leading underscores
[minetest.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 "irrlichttypes_bloated.h"
24
25 class ServerEnvironment;
26 class NodeMetadata;
27
28 /*
29         NodeMetaRef
30 */
31
32 class NodeMetaRef : public ModApiBase {
33 private:
34         v3s16 m_p;
35         ServerEnvironment *m_env;
36
37         static const char className[];
38         static const luaL_reg methods[];
39
40         static NodeMetaRef *checkobject(lua_State *L, int narg);
41
42         /**
43          * Retrieve metadata for a node.
44          * If @p auto_create is set and the specified node has no metadata information
45          * associated with it yet, the method attempts to attach a new metadata object
46          * to the node and returns a pointer to the metadata when successful.
47          *
48          * However, it is NOT guaranteed that the method will return a pointer,
49          * and @c NULL may be returned in case of an error regardless of @p auto_create.
50          *
51          * @param ref specifies the node for which the associated metadata is retrieved.
52          * @param auto_create when true, try to create metadata information for the node if it has none.
53          * @return pointer to a @c NodeMetadata object or @c NULL in case of error.
54          */
55         static NodeMetadata* getmeta(NodeMetaRef *ref, bool auto_create);
56
57         static void reportMetadataChange(NodeMetaRef *ref);
58
59         // Exported functions
60
61         // garbage collector
62         static int gc_object(lua_State *L);
63
64         // get_string(self, name)
65         static int l_get_string(lua_State *L);
66
67         // set_string(self, name, var)
68         static int l_set_string(lua_State *L);
69
70         // get_int(self, name)
71         static int l_get_int(lua_State *L);
72
73         // set_int(self, name, var)
74         static int l_set_int(lua_State *L);
75
76         // get_float(self, name)
77         static int l_get_float(lua_State *L);
78
79         // set_float(self, name, var)
80         static int l_set_float(lua_State *L);
81
82         // get_inventory(self)
83         static int l_get_inventory(lua_State *L);
84
85         // to_table(self)
86         static int l_to_table(lua_State *L);
87
88         // from_table(self, table)
89         static int l_from_table(lua_State *L);
90
91 public:
92         NodeMetaRef(v3s16 p, ServerEnvironment *env);
93
94         ~NodeMetaRef();
95
96         // Creates an NodeMetaRef and leaves it on top of stack
97         // Not callable from Lua; all references are created on the C side.
98         static void create(lua_State *L, v3s16 p, ServerEnvironment *env);
99
100         static void Register(lua_State *L);
101 };
102
103 #endif /* L_NODEMETA_H_ */