Skip to content

Commit 63c892e

Browse files
committedJan 16, 2017
Rename ObjectRef methods to be consistent and predictable
1 parent f3bd4c4 commit 63c892e

File tree

4 files changed

+67
-66
lines changed

4 files changed

+67
-66
lines changed
 

‎doc/lua_api.txt

+11-11
Original file line numberDiff line numberDiff line change
@@ -2788,9 +2788,9 @@ This is basically a reference to a C++ `ServerActiveObject`
27882788
#### Methods
27892789
* `remove()`: remove object (after returning from Lua)
27902790
* Note: Doesn't work on players, use minetest.kick_player instead
2791-
* `getpos()`: returns `{x=num, y=num, z=num}`
2792-
* `setpos(pos)`; `pos`=`{x=num, y=num, z=num}`
2793-
* `moveto(pos, continuous=false)`: interpolated move
2791+
* `get_pos()`: returns `{x=num, y=num, z=num}`
2792+
* `set_pos(pos)`; `pos`=`{x=num, y=num, z=num}`
2793+
* `move_to(pos, continuous=false)`: interpolated move
27942794
* `punch(puncher, time_from_last_punch, tool_capabilities, direction)`
27952795
* `puncher` = another `ObjectRef`,
27962796
* `time_from_last_punch` = time since last punch action of the puncher
@@ -2836,14 +2836,14 @@ This is basically a reference to a C++ `ServerActiveObject`
28362836
}
28372837

28382838
##### LuaEntitySAO-only (no-op for other objects)
2839-
* `setvelocity({x=num, y=num, z=num})`
2840-
* `getvelocity()`: returns `{x=num, y=num, z=num}`
2841-
* `setacceleration({x=num, y=num, z=num})`
2842-
* `getacceleration()`: returns `{x=num, y=num, z=num}`
2843-
* `setyaw(radians)`
2844-
* `getyaw()`: returns number in radians
2845-
* `settexturemod(mod)`
2846-
* `setsprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
2839+
* `set_velocity({x=num, y=num, z=num})`
2840+
* `get_velocity()`: returns `{x=num, y=num, z=num}`
2841+
* `set_acceleration({x=num, y=num, z=num})`
2842+
* `get_acceleration()`: returns `{x=num, y=num, z=num}`
2843+
* `set_yaw(radians)`
2844+
* `get_yaw()`: returns number in radians
2845+
* `set_texture_mod(mod)`
2846+
* `set_sprite(p={x=0,y=0}, num_frames=1, framelength=0.2,
28472847
select_horiz_by_yawpitch=false)`
28482848
* Select sprite from spritesheet with optional animation and DM-style
28492849
texture selection based on yaw relative to camera

‎src/script/lua_api/l_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3030
#include "common/c_internal.h"
3131

3232
#define luamethod(class, name) {#name, class::l_##name}
33+
#define luamethod_aliased(class, name, alias) {#name, class::l_##name}, {#alias, class::l_##name}
3334
#define API_FCT(name) registerFunction(L, #name, l_##name,top)
3435
#define ASYNC_API_FCT(name) engine.registerFunction(#name, l_##name)
3536

‎src/script/lua_api/l_object.cpp

+33-33
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ int ObjectRef::l_remove(lua_State *L)
150150
return 0;
151151
}
152152

153-
// getpos(self)
153+
// get_pos(self)
154154
// returns: {x=num, y=num, z=num}
155-
int ObjectRef::l_getpos(lua_State *L)
155+
int ObjectRef::l_get_pos(lua_State *L)
156156
{
157157
NO_MAP_LOCK_REQUIRED;
158158
ObjectRef *ref = checkobject(L, 1);
@@ -169,8 +169,8 @@ int ObjectRef::l_getpos(lua_State *L)
169169
return 1;
170170
}
171171

172-
// setpos(self, pos)
173-
int ObjectRef::l_setpos(lua_State *L)
172+
// set_pos(self, pos)
173+
int ObjectRef::l_set_pos(lua_State *L)
174174
{
175175
NO_MAP_LOCK_REQUIRED;
176176
ObjectRef *ref = checkobject(L, 1);
@@ -184,8 +184,8 @@ int ObjectRef::l_setpos(lua_State *L)
184184
return 0;
185185
}
186186

187-
// moveto(self, pos, continuous=false)
188-
int ObjectRef::l_moveto(lua_State *L)
187+
// move_to(self, pos, continuous=false)
188+
int ObjectRef::l_move_to(lua_State *L)
189189
{
190190
NO_MAP_LOCK_REQUIRED;
191191
ObjectRef *ref = checkobject(L, 1);
@@ -821,8 +821,8 @@ int ObjectRef::l_get_nametag_attributes(lua_State *L)
821821

822822
/* LuaEntitySAO-only */
823823

824-
// setvelocity(self, {x=num, y=num, z=num})
825-
int ObjectRef::l_setvelocity(lua_State *L)
824+
// set_velocity(self, {x=num, y=num, z=num})
825+
int ObjectRef::l_set_velocity(lua_State *L)
826826
{
827827
NO_MAP_LOCK_REQUIRED;
828828
ObjectRef *ref = checkobject(L, 1);
@@ -834,8 +834,8 @@ int ObjectRef::l_setvelocity(lua_State *L)
834834
return 0;
835835
}
836836

837-
// getvelocity(self)
838-
int ObjectRef::l_getvelocity(lua_State *L)
837+
// get_velocity(self)
838+
int ObjectRef::l_get_velocity(lua_State *L)
839839
{
840840
NO_MAP_LOCK_REQUIRED;
841841
ObjectRef *ref = checkobject(L, 1);
@@ -847,8 +847,8 @@ int ObjectRef::l_getvelocity(lua_State *L)
847847
return 1;
848848
}
849849

850-
// setacceleration(self, {x=num, y=num, z=num})
851-
int ObjectRef::l_setacceleration(lua_State *L)
850+
// set_acceleration(self, {x=num, y=num, z=num})
851+
int ObjectRef::l_set_acceleration(lua_State *L)
852852
{
853853
NO_MAP_LOCK_REQUIRED;
854854
ObjectRef *ref = checkobject(L, 1);
@@ -861,8 +861,8 @@ int ObjectRef::l_setacceleration(lua_State *L)
861861
return 0;
862862
}
863863

864-
// getacceleration(self)
865-
int ObjectRef::l_getacceleration(lua_State *L)
864+
// get_acceleration(self)
865+
int ObjectRef::l_get_acceleration(lua_State *L)
866866
{
867867
NO_MAP_LOCK_REQUIRED;
868868
ObjectRef *ref = checkobject(L, 1);
@@ -874,8 +874,8 @@ int ObjectRef::l_getacceleration(lua_State *L)
874874
return 1;
875875
}
876876

877-
// setyaw(self, radians)
878-
int ObjectRef::l_setyaw(lua_State *L)
877+
// set_yaw(self, radians)
878+
int ObjectRef::l_set_yaw(lua_State *L)
879879
{
880880
NO_MAP_LOCK_REQUIRED;
881881
ObjectRef *ref = checkobject(L, 1);
@@ -887,8 +887,8 @@ int ObjectRef::l_setyaw(lua_State *L)
887887
return 0;
888888
}
889889

890-
// getyaw(self)
891-
int ObjectRef::l_getyaw(lua_State *L)
890+
// get_yaw(self)
891+
int ObjectRef::l_get_yaw(lua_State *L)
892892
{
893893
NO_MAP_LOCK_REQUIRED;
894894
ObjectRef *ref = checkobject(L, 1);
@@ -900,8 +900,8 @@ int ObjectRef::l_getyaw(lua_State *L)
900900
return 1;
901901
}
902902

903-
// settexturemod(self, mod)
904-
int ObjectRef::l_settexturemod(lua_State *L)
903+
// set_texture_mod(self, mod)
904+
int ObjectRef::l_set_texture_mod(lua_State *L)
905905
{
906906
NO_MAP_LOCK_REQUIRED;
907907
ObjectRef *ref = checkobject(L, 1);
@@ -913,9 +913,9 @@ int ObjectRef::l_settexturemod(lua_State *L)
913913
return 0;
914914
}
915915

916-
// setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
916+
// set_sprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
917917
// select_horiz_by_yawpitch=false)
918-
int ObjectRef::l_setsprite(lua_State *L)
918+
int ObjectRef::l_set_sprite(lua_State *L)
919919
{
920920
NO_MAP_LOCK_REQUIRED;
921921
ObjectRef *ref = checkobject(L, 1);
@@ -1774,9 +1774,9 @@ const char ObjectRef::className[] = "ObjectRef";
17741774
const luaL_reg ObjectRef::methods[] = {
17751775
// ServerActiveObject
17761776
luamethod(ObjectRef, remove),
1777-
luamethod(ObjectRef, getpos),
1778-
luamethod(ObjectRef, setpos),
1779-
luamethod(ObjectRef, moveto),
1777+
luamethod_aliased(ObjectRef, get_pos, getpos),
1778+
luamethod_aliased(ObjectRef, set_pos, setpos),
1779+
luamethod_aliased(ObjectRef, move_to, moveto),
17801780
luamethod(ObjectRef, punch),
17811781
luamethod(ObjectRef, right_click),
17821782
luamethod(ObjectRef, set_hp),
@@ -1800,14 +1800,14 @@ const luaL_reg ObjectRef::methods[] = {
18001800
luamethod(ObjectRef, set_nametag_attributes),
18011801
luamethod(ObjectRef, get_nametag_attributes),
18021802
// LuaEntitySAO-only
1803-
luamethod(ObjectRef, setvelocity),
1804-
luamethod(ObjectRef, getvelocity),
1805-
luamethod(ObjectRef, setacceleration),
1806-
luamethod(ObjectRef, getacceleration),
1807-
luamethod(ObjectRef, setyaw),
1808-
luamethod(ObjectRef, getyaw),
1809-
luamethod(ObjectRef, settexturemod),
1810-
luamethod(ObjectRef, setsprite),
1803+
luamethod_aliased(ObjectRef, set_velocity, setvelocity),
1804+
luamethod_aliased(ObjectRef, get_velocity, getvelocity),
1805+
luamethod_aliased(ObjectRef, set_acceleration, setacceleration),
1806+
luamethod_aliased(ObjectRef, get_acceleration, getacceleration),
1807+
luamethod_aliased(ObjectRef, set_yaw, setyaw),
1808+
luamethod_aliased(ObjectRef, get_yaw, getyaw),
1809+
luamethod_aliased(ObjectRef, set_texture_mod, set_texturemod),
1810+
luamethod_aliased(ObjectRef, set_sprite, setsprite),
18111811
luamethod(ObjectRef, get_entity_name),
18121812
luamethod(ObjectRef, get_luaentity),
18131813
// Player-only

‎src/script/lua_api/l_object.h

+22-22
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ class ObjectRef : public ModApiBase {
5757
// remove(self)
5858
static int l_remove(lua_State *L);
5959

60-
// getpos(self)
60+
// get_pos(self)
6161
// returns: {x=num, y=num, z=num}
62-
static int l_getpos(lua_State *L);
62+
static int l_get_pos(lua_State *L);
6363

64-
// setpos(self, pos)
65-
static int l_setpos(lua_State *L);
64+
// set_pos(self, pos)
65+
static int l_set_pos(lua_State *L);
6666

67-
// moveto(self, pos, continuous=false)
68-
static int l_moveto(lua_State *L);
67+
// move_to(self, pos, continuous=false)
68+
static int l_move_to(lua_State *L);
6969

7070
// punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
7171
static int l_punch(lua_State *L);
@@ -143,30 +143,30 @@ class ObjectRef : public ModApiBase {
143143

144144
/* LuaEntitySAO-only */
145145

146-
// setvelocity(self, {x=num, y=num, z=num})
147-
static int l_setvelocity(lua_State *L);
146+
// set_velocity(self, {x=num, y=num, z=num})
147+
static int l_set_velocity(lua_State *L);
148148

149-
// getvelocity(self)
150-
static int l_getvelocity(lua_State *L);
149+
// get_velocity(self)
150+
static int l_get_velocity(lua_State *L);
151151

152-
// setacceleration(self, {x=num, y=num, z=num})
153-
static int l_setacceleration(lua_State *L);
152+
// set_acceleration(self, {x=num, y=num, z=num})
153+
static int l_set_acceleration(lua_State *L);
154154

155-
// getacceleration(self)
156-
static int l_getacceleration(lua_State *L);
155+
// get_acceleration(self)
156+
static int l_get_acceleration(lua_State *L);
157157

158-
// setyaw(self, radians)
159-
static int l_setyaw(lua_State *L);
158+
// set_yaw(self, radians)
159+
static int l_set_yaw(lua_State *L);
160160

161-
// getyaw(self)
162-
static int l_getyaw(lua_State *L);
161+
// get_yaw(self)
162+
static int l_get_yaw(lua_State *L);
163163

164-
// settexturemod(self, mod)
165-
static int l_settexturemod(lua_State *L);
164+
// set_texture_mod(self, mod)
165+
static int l_set_texture_mod(lua_State *L);
166166

167-
// setsprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
167+
// set_sprite(self, p={x=0,y=0}, num_frames=1, framelength=0.2,
168168
// select_horiz_by_yawpitch=false)
169-
static int l_setsprite(lua_State *L);
169+
static int l_set_sprite(lua_State *L);
170170

171171
// DEPRECATED
172172
// get_entity_name(self)

0 commit comments

Comments
 (0)
Please sign in to comment.