]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/lua_api/l_object.h
Move scriptapi to separate folder (by sapier)
[dragonfireclient.git] / src / script / lua_api / l_object.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
20 #ifndef L_OBJECT_H_
21 #define L_OBJECT_H_
22
23 extern "C" {
24 #include <lua.h>
25 #include <lauxlib.h>
26 }
27
28 class ServerActiveObject;
29 class LuaEntitySAO;
30 class PlayerSAO;
31 class Player;
32
33 /*
34         ObjectRef
35 */
36
37 class ObjectRef
38 {
39 private:
40         ServerActiveObject *m_object;
41
42         static const char className[];
43         static const luaL_reg methods[];
44 public:
45         static ObjectRef *checkobject(lua_State *L, int narg);
46
47         static ServerActiveObject* getobject(ObjectRef *ref);
48 private:
49         static LuaEntitySAO* getluaobject(ObjectRef *ref);
50
51         static PlayerSAO* getplayersao(ObjectRef *ref);
52
53         static Player* getplayer(ObjectRef *ref);
54
55         // Exported functions
56
57         // garbage collector
58         static int gc_object(lua_State *L);
59
60         // remove(self)
61         static int l_remove(lua_State *L);
62
63         // getpos(self)
64         // returns: {x=num, y=num, z=num}
65         static int l_getpos(lua_State *L);
66
67         // setpos(self, pos)
68         static int l_setpos(lua_State *L);
69
70         // moveto(self, pos, continuous=false)
71         static int l_moveto(lua_State *L);
72
73         // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
74         static int l_punch(lua_State *L);
75
76         // right_click(self, clicker); clicker = an another ObjectRef
77         static int l_right_click(lua_State *L);
78
79         // set_hp(self, hp)
80         // hp = number of hitpoints (2 * number of hearts)
81         // returns: nil
82         static int l_set_hp(lua_State *L);
83
84         // get_hp(self)
85         // returns: number of hitpoints (2 * number of hearts)
86         // 0 if not applicable to this type of object
87         static int l_get_hp(lua_State *L);
88
89         // get_inventory(self)
90         static int l_get_inventory(lua_State *L);
91
92         // get_wield_list(self)
93         static int l_get_wield_list(lua_State *L);
94
95         // get_wield_index(self)
96         static int l_get_wield_index(lua_State *L);
97
98         // get_wielded_item(self)
99         static int l_get_wielded_item(lua_State *L);
100
101         // set_wielded_item(self, itemstack or itemstring or table or nil)
102         static int l_set_wielded_item(lua_State *L);
103
104         // set_armor_groups(self, groups)
105         static int l_set_armor_groups(lua_State *L);
106
107         // set_physics_override(self, physics_override_speed, physics_override_jump, physics_override_gravity)
108         static int l_set_physics_override(lua_State *L);
109
110         // set_animation(self, frame_range, frame_speed, frame_blend)
111         static int l_set_animation(lua_State *L);
112
113         // set_bone_position(self, std::string bone, v3f position, v3f rotation)
114         static int l_set_bone_position(lua_State *L);
115
116         // set_attach(self, parent, bone, position, rotation)
117         static int l_set_attach(lua_State *L);
118
119         // set_detach(self)
120         static int l_set_detach(lua_State *L);
121
122         // set_properties(self, properties)
123         static int l_set_properties(lua_State *L);
124
125         /* LuaEntitySAO-only */
126
127         // setvelocity(self, {x=num, y=num, z=num})
128         static int l_setvelocity(lua_State *L);
129
130         // getvelocity(self)
131         static int l_getvelocity(lua_State *L);
132
133         // setacceleration(self, {x=num, y=num, z=num})
134         static int l_setacceleration(lua_State *L);
135
136         // getacceleration(self)
137         static int l_getacceleration(lua_State *L);
138
139         // setyaw(self, radians)
140         static int l_setyaw(lua_State *L);
141
142         // getyaw(self)
143         static int l_getyaw(lua_State *L);
144
145         // settexturemod(self, mod)
146         static int l_settexturemod(lua_State *L);
147
148         // setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
149         //           select_horiz_by_yawpitch=false)
150         static int l_setsprite(lua_State *L);
151
152         // DEPRECATED
153         // get_entity_name(self)
154         static int l_get_entity_name(lua_State *L);
155
156         // get_luaentity(self)
157         static int l_get_luaentity(lua_State *L);
158
159         /* Player-only */
160
161         // is_player(self)
162         static int l_is_player(lua_State *L);
163
164         // get_player_name(self)
165         static int l_get_player_name(lua_State *L);
166
167         // get_look_dir(self)
168         static int l_get_look_dir(lua_State *L);
169
170         // get_look_pitch(self)
171         static int l_get_look_pitch(lua_State *L);
172
173         // get_look_yaw(self)
174         static int l_get_look_yaw(lua_State *L);
175
176         // set_look_pitch(self, radians)
177         static int l_set_look_pitch(lua_State *L);
178
179         // set_look_yaw(self, radians)
180         static int l_set_look_yaw(lua_State *L);
181
182         // set_inventory_formspec(self, formspec)
183         static int l_set_inventory_formspec(lua_State *L);
184
185         // get_inventory_formspec(self) -> formspec
186         static int l_get_inventory_formspec(lua_State *L);
187
188         // get_player_control(self)
189         static int l_get_player_control(lua_State *L);
190
191         // get_player_control_bits(self)
192         static int l_get_player_control_bits(lua_State *L);
193
194         // hud_add(self, id, form)
195         static int l_hud_add(lua_State *L);
196
197         // hud_rm(self, id)
198         static int l_hud_remove(lua_State *L);
199
200         // hud_change(self, id, stat, data)
201         static int l_hud_change(lua_State *L);
202
203         // hud_get_next_id(self)
204         static u32 hud_get_next_id(lua_State *L);
205
206         // hud_get(self, id)
207         static int l_hud_get(lua_State *L);
208
209         // hud_set_flags(self, flags)
210         static int l_hud_set_flags(lua_State *L);
211
212 public:
213         ObjectRef(ServerActiveObject *object);
214
215         ~ObjectRef();
216
217         // Creates an ObjectRef and leaves it on top of stack
218         // Not callable from Lua; all references are created on the C side.
219         static void create(lua_State *L, ServerActiveObject *object);
220
221         static void set_null(lua_State *L);
222
223         static void Register(lua_State *L);
224 };
225
226 #endif /* L_OBJECT_H_ */