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 
20 
21 /******************************************************************************/
22 /******************************************************************************/
23 /* WARNING!!!! do NOT add this header in any include file or any code file    */
24 /*             not being a script/modapi file!!!!!!!!                         */
25 /******************************************************************************/
26 /******************************************************************************/
27 
28 #pragma once
29 
30 extern "C" {
31 #include <lua.h>
32 }
33 
34 #include <iostream>
35 #include <vector>
36 
37 #include "irrlichttypes_bloated.h"
38 #include "util/string.h"
39 #include "itemgroup.h"
40 #include "itemdef.h"
41 #include "c_types.h"
42 #include "hud.h"
43 
44 namespace Json { class Value; }
45 
46 struct MapNode;
47 class NodeDefManager;
48 struct PointedThing;
49 struct ItemStack;
50 struct ItemDefinition;
51 struct ToolCapabilities;
52 struct ObjectProperties;
53 struct SimpleSoundSpec;
54 struct ServerSoundParams;
55 class Inventory;
56 struct NodeBox;
57 struct ContentFeatures;
58 struct TileDef;
59 class Server;
60 struct DigParams;
61 struct HitParams;
62 struct EnumString;
63 struct NoiseParams;
64 class Schematic;
65 class ServerActiveObject;
66 struct collisionMoveResult;
67 
68 extern struct EnumString es_TileAnimationType[];
69 
70 void               read_content_features     (lua_State *L, ContentFeatures &f,
71                                               int index);
72 void               push_content_features     (lua_State *L,
73                                               const ContentFeatures &c);
74 
75 void               push_nodebox              (lua_State *L,
76                                               const NodeBox &box);
77 void               push_box                  (lua_State *L,
78                                               const std::vector<aabb3f> &box);
79 
80 void               push_palette              (lua_State *L,
81                                               const std::vector<video::SColor> *palette);
82 
83 TileDef            read_tiledef              (lua_State *L, int index,
84                                               u8 drawtype);
85 
86 void               read_soundspec            (lua_State *L, int index,
87                                               SimpleSoundSpec &spec);
88 NodeBox            read_nodebox              (lua_State *L, int index);
89 
90 void               read_server_sound_params  (lua_State *L, int index,
91                                               ServerSoundParams &params);
92 
93 void               push_dig_params           (lua_State *L,
94                                               const DigParams &params);
95 void               push_hit_params           (lua_State *L,
96                                               const HitParams &params);
97 
98 ItemStack          read_item                 (lua_State *L, int index, IItemDefManager *idef);
99 
100 struct TileAnimationParams read_animation_definition(lua_State *L, int index);
101 
102 ToolCapabilities   read_tool_capabilities    (lua_State *L, int table);
103 void               push_tool_capabilities    (lua_State *L,
104                                               const ToolCapabilities &prop);
105 
106 void read_item_definition (lua_State *L, int index, const ItemDefinition &default_def,
107 		ItemDefinition &def);
108 void               push_item_definition      (lua_State *L,
109                                               const ItemDefinition &i);
110 void               push_item_definition_full (lua_State *L,
111                                               const ItemDefinition &i);
112 
113 void               read_object_properties    (lua_State *L, int index,
114                                               ServerActiveObject *sao,
115                                               ObjectProperties *prop,
116                                               IItemDefManager *idef);
117 void               push_object_properties    (lua_State *L,
118                                               ObjectProperties *prop);
119 
120 void               push_inventory_list       (lua_State *L,
121                                               Inventory *inv,
122                                               const char *name);
123 void               read_inventory_list       (lua_State *L, int tableindex,
124                                               Inventory *inv, const char *name,
125                                               Server *srv, int forcesize=-1);
126 
127 MapNode            readnode                  (lua_State *L, int index,
128                                               const NodeDefManager *ndef);
129 void               pushnode                  (lua_State *L, const MapNode &n,
130                                               const NodeDefManager *ndef);
131 
132 
133 void               read_groups               (lua_State *L, int index,
134                                               ItemGroupList &result);
135 
136 void               push_groups               (lua_State *L,
137                                               const ItemGroupList &groups);
138 
139 //TODO rename to "read_enum_field"
140 int                getenumfield              (lua_State *L, int table,
141                                               const char *fieldname,
142                                               const EnumString *spec,
143                                               int default_);
144 
145 bool               getflagsfield             (lua_State *L, int table,
146                                               const char *fieldname,
147                                               FlagDesc *flagdesc,
148                                               u32 *flags, u32 *flagmask);
149 
150 bool               read_flags                (lua_State *L, int index,
151                                               FlagDesc *flagdesc,
152                                               u32 *flags, u32 *flagmask);
153 
154 void               push_flags_string         (lua_State *L, FlagDesc *flagdesc,
155                                               u32 flags, u32 flagmask);
156 
157 u32                read_flags_table          (lua_State *L, int table,
158                                               FlagDesc *flagdesc, u32 *flagmask);
159 
160 void               push_items                (lua_State *L,
161                                               const std::vector<ItemStack> &items);
162 
163 std::vector<ItemStack> read_items            (lua_State *L,
164                                               int index,
165                                               Server* srv);
166 
167 void               push_soundspec            (lua_State *L,
168                                               const SimpleSoundSpec &spec);
169 
170 bool               string_to_enum            (const EnumString *spec,
171                                               int &result,
172                                               const std::string &str);
173 
174 bool               read_noiseparams          (lua_State *L, int index,
175                                               NoiseParams *np);
176 void               push_noiseparams          (lua_State *L, NoiseParams *np);
177 
178 void               luaentity_get             (lua_State *L,u16 id);
179 
180 bool               push_json_value           (lua_State *L,
181                                               const Json::Value &value,
182                                               int nullindex);
183 void               read_json_value           (lua_State *L, Json::Value &root,
184                                               int index, u8 recursion = 0);
185 
186 /*!
187  * Pushes a Lua `pointed_thing` to the given Lua stack.
188  * \param csm If true, a client side pointed thing is pushed
189  * \param hitpoint If true, the exact pointing location is also pushed
190  */
191 void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm =
192 	false, bool hitpoint = false);
193 
194 void               push_objectRef            (lua_State *L, const u16 id);
195 
196 void               read_hud_element          (lua_State *L, HudElement *elem);
197 
198 void               push_hud_element          (lua_State *L, HudElement *elem);
199 
200 HudElementStat     read_hud_change           (lua_State *L, HudElement *elem, void **value);
201 
202 void               push_collision_move_result(lua_State *L, const collisionMoveResult &res);
203