]> git.lizzy.rs Git - dragonfireclient.git/blob - src/scriptapi_nodemeta.h
split scriptapi.cpp
[dragonfireclient.git] / src / scriptapi_nodemeta.h
1 /*
2 Minetest-c55
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 LUA_NODEMETA_H_
20 #define LUA_NODEMETA_H_
21
22 #include <irr_v3d.h>
23
24 extern "C" {
25 #include <lua.h>
26 #include <lauxlib.h>
27 }
28
29 #include "environment.h"
30 #include "nodemetadata.h"
31
32 /*
33         NodeMetaRef
34 */
35
36 class NodeMetaRef
37 {
38 private:
39         v3s16 m_p;
40         ServerEnvironment *m_env;
41
42         static const char className[];
43         static const luaL_reg methods[];
44
45         static NodeMetaRef *checkobject(lua_State *L, int narg);
46
47         static NodeMetadata* getmeta(NodeMetaRef *ref, bool auto_create);
48
49         static void reportMetadataChange(NodeMetaRef *ref);
50
51         // Exported functions
52
53         // garbage collector
54         static int gc_object(lua_State *L);
55
56         // get_string(self, name)
57         static int l_get_string(lua_State *L);
58
59         // set_string(self, name, var)
60         static int l_set_string(lua_State *L);
61
62         // get_int(self, name)
63         static int l_get_int(lua_State *L);
64
65         // set_int(self, name, var)
66         static int l_set_int(lua_State *L);
67
68         // get_float(self, name)
69         static int l_get_float(lua_State *L);
70
71         // set_float(self, name, var)
72         static int l_set_float(lua_State *L);
73
74         // get_inventory(self)
75         static int l_get_inventory(lua_State *L);
76
77         // to_table(self)
78         static int l_to_table(lua_State *L);
79
80         // from_table(self, table)
81         static int l_from_table(lua_State *L);
82
83 public:
84         NodeMetaRef(v3s16 p, ServerEnvironment *env);
85
86         ~NodeMetaRef();
87
88         // Creates an NodeMetaRef and leaves it on top of stack
89         // Not callable from Lua; all references are created on the C side.
90         static void create(lua_State *L, v3s16 p, ServerEnvironment *env);
91
92         static void Register(lua_State *L);
93 };
94
95 /*****************************************************************************/
96 /* Minetest interface                                                        */
97 /*****************************************************************************/
98 // Return number of accepted items to be moved
99 int scriptapi_nodemeta_inventory_allow_move(lua_State *L, v3s16 p,
100                 const std::string &from_list, int from_index,
101                 const std::string &to_list, int to_index,
102                 int count, ServerActiveObject *player);
103 // Return number of accepted items to be put
104 int scriptapi_nodemeta_inventory_allow_put(lua_State *L, v3s16 p,
105                 const std::string &listname, int index, ItemStack &stack,
106                 ServerActiveObject *player);
107 // Return number of accepted items to be taken
108 int scriptapi_nodemeta_inventory_allow_take(lua_State *L, v3s16 p,
109                 const std::string &listname, int index, ItemStack &stack,
110                 ServerActiveObject *player);
111 // Report moved items
112 void scriptapi_nodemeta_inventory_on_move(lua_State *L, v3s16 p,
113                 const std::string &from_list, int from_index,
114                 const std::string &to_list, int to_index,
115                 int count, ServerActiveObject *player);
116 // Report put items
117 void scriptapi_nodemeta_inventory_on_put(lua_State *L, v3s16 p,
118                 const std::string &listname, int index, ItemStack &stack,
119                 ServerActiveObject *player);
120 // Report taken items
121 void scriptapi_nodemeta_inventory_on_take(lua_State *L, v3s16 p,
122                 const std::string &listname, int index, ItemStack &stack,
123                 ServerActiveObject *player);
124
125 #endif //LUA_NODEMETA_H_