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.
19 #ifndef LUA_NODEMETA_H_
20 #define LUA_NODEMETA_H_
27 #include "environment.h"
28 #include "nodemetadata.h"
38 ServerEnvironment *m_env;
40 static const char className[];
41 static const luaL_reg methods[];
43 static NodeMetaRef *checkobject(lua_State *L, int narg);
45 static NodeMetadata* getmeta(NodeMetaRef *ref, bool auto_create);
47 static void reportMetadataChange(NodeMetaRef *ref);
52 static int gc_object(lua_State *L);
54 // get_string(self, name)
55 static int l_get_string(lua_State *L);
57 // set_string(self, name, var)
58 static int l_set_string(lua_State *L);
60 // get_int(self, name)
61 static int l_get_int(lua_State *L);
63 // set_int(self, name, var)
64 static int l_set_int(lua_State *L);
66 // get_float(self, name)
67 static int l_get_float(lua_State *L);
69 // set_float(self, name, var)
70 static int l_set_float(lua_State *L);
72 // get_inventory(self)
73 static int l_get_inventory(lua_State *L);
76 static int l_to_table(lua_State *L);
78 // from_table(self, table)
79 static int l_from_table(lua_State *L);
82 NodeMetaRef(v3s16 p, ServerEnvironment *env);
86 // Creates an NodeMetaRef and leaves it on top of stack
87 // Not callable from Lua; all references are created on the C side.
88 static void create(lua_State *L, v3s16 p, ServerEnvironment *env);
90 static void Register(lua_State *L);
93 /*****************************************************************************/
94 /* Minetest interface */
95 /*****************************************************************************/
96 // Return number of accepted items to be moved
97 int scriptapi_nodemeta_inventory_allow_move(lua_State *L, v3s16 p,
98 const std::string &from_list, int from_index,
99 const std::string &to_list, int to_index,
100 int count, ServerActiveObject *player);
101 // Return number of accepted items to be put
102 int scriptapi_nodemeta_inventory_allow_put(lua_State *L, v3s16 p,
103 const std::string &listname, int index, ItemStack &stack,
104 ServerActiveObject *player);
105 // Return number of accepted items to be taken
106 int scriptapi_nodemeta_inventory_allow_take(lua_State *L, v3s16 p,
107 const std::string &listname, int index, ItemStack &stack,
108 ServerActiveObject *player);
109 // Report moved items
110 void scriptapi_nodemeta_inventory_on_move(lua_State *L, v3s16 p,
111 const std::string &from_list, int from_index,
112 const std::string &to_list, int to_index,
113 int count, ServerActiveObject *player);
115 void scriptapi_nodemeta_inventory_on_put(lua_State *L, v3s16 p,
116 const std::string &listname, int index, ItemStack &stack,
117 ServerActiveObject *player);
118 // Report taken items
119 void scriptapi_nodemeta_inventory_on_take(lua_State *L, v3s16 p,
120 const std::string &listname, int index, ItemStack &stack,
121 ServerActiveObject *player);
123 #endif //LUA_NODEMETA_H_