summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_object.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2018-06-30 17:11:38 +0200
committerGitHub <noreply@github.com>2018-06-30 17:11:38 +0200
commiteef62c82a2e58700fc1216b0b8c03e421bc77995 (patch)
tree4c49e659069036cb53d69535dc33d33f29d963f4 /src/script/lua_api/l_object.cpp
parent227c71eb76e019873b30e2d3893b68307d51d58f (diff)
downloadminetest-eef62c82a2e58700fc1216b0b8c03e421bc77995.tar.gz
minetest-eef62c82a2e58700fc1216b0b8c03e421bc77995.tar.bz2
minetest-eef62c82a2e58700fc1216b0b8c03e421bc77995.zip
Modernize lua read (part 2 & 3): C++ templating assurance (#7410)
* Modernize lua read (part 2 & 3): C++ templating assurance Implement the boolean reader Implement the string reader Also remove unused & unimplemented script_error_handler Add a reader with default value
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r--src/script/lua_api/l_object.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index f87c02a6d..b6f37d51b 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -156,7 +156,7 @@ int ObjectRef::l_move_to(lua_State *L)
// pos
v3f pos = checkFloatPos(L, 2);
// continuous
- bool continuous = lua_toboolean(L, 3);
+ bool continuous = readParam<bool>(L, 3);
// Do it
co->moveTo(pos, continuous);
return 0;
@@ -243,7 +243,8 @@ int ObjectRef::l_set_hp(lua_State *L)
lua_pushvalue(L, 3);
lua_getfield(L, -1, "type");
- if (lua_isstring(L, -1) && !reason.setTypeFromString(lua_tostring(L, -1))) {
+ if (lua_isstring(L, -1) &&
+ !reason.setTypeFromString(readParam<std::string>(L, -1))) {
errorstream << "Bad type given!" << std::endl;
}
lua_pop(L, 1);
@@ -466,7 +467,7 @@ int ObjectRef::l_set_animation(lua_State *L)
frame_blend = lua_tonumber(L, 4);
bool frame_loop = true;
if (lua_isboolean(L, 5))
- frame_loop = lua_toboolean(L, 5);
+ frame_loop = readParam<bool>(L, 5);
co->setAnimation(frames, frame_speed, frame_blend, frame_loop);
return 0;
}
@@ -609,7 +610,7 @@ int ObjectRef::l_set_bone_position(lua_State *L)
// Do it
std::string bone;
if (!lua_isnil(L, 2))
- bone = lua_tostring(L, 2);
+ bone = readParam<std::string>(L, 2);
v3f position = v3f(0, 0, 0);
if (!lua_isnil(L, 3))
position = check_v3f(L, 3);
@@ -631,7 +632,7 @@ int ObjectRef::l_get_bone_position(lua_State *L)
// Do it
std::string bone;
if (!lua_isnil(L, 2))
- bone = lua_tostring(L, 2);
+ bone = readParam<std::string>(L, 2);
v3f position = v3f(0, 0, 0);
v3f rotation = v3f(0, 0, 0);
@@ -668,7 +669,7 @@ int ObjectRef::l_set_attach(lua_State *L)
bone = "";
if (!lua_isnil(L, 3))
- bone = lua_tostring(L, 3);
+ bone = readParam<std::string>(L, 3);
position = v3f(0, 0, 0);
if (!lua_isnil(L, 4))
position = read_v3f(L, 4);
@@ -963,7 +964,7 @@ int ObjectRef::l_set_sprite(lua_State *L)
framelength = lua_tonumber(L, 4);
bool select_horiz_by_yawpitch = false;
if (!lua_isnil(L, 5))
- select_horiz_by_yawpitch = lua_toboolean(L, 5);
+ select_horiz_by_yawpitch = readParam<bool>(L, 5);
co->setSprite(p, num_frames, framelength, select_horiz_by_yawpitch);
return 0;
}
@@ -1536,7 +1537,7 @@ int ObjectRef::l_hud_set_hotbar_image(lua_State *L)
if (player == NULL)
return 0;
- std::string name = lua_tostring(L, 2);
+ std::string name = readParam<std::string>(L, 2);
getServer(L)->hudSetHotbarImage(player, name);
return 1;
@@ -1565,7 +1566,7 @@ int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L)
if (player == NULL)
return 0;
- std::string name = lua_tostring(L, 2);
+ std::string name = readParam<std::string>(L, 2);
getServer(L)->hudSetHotbarSelectedImage(player, name);
return 1;
@@ -1605,7 +1606,7 @@ int ObjectRef::l_set_sky(lua_State *L)
while (lua_next(L, 4) != 0) {
// key at index -2 and value at index -1
if (lua_isstring(L, -1))
- params.emplace_back(lua_tostring(L, -1));
+ params.emplace_back(readParam<std::string>(L, -1));
else
params.emplace_back("");
// removes value, keeps key for next iteration
@@ -1618,7 +1619,7 @@ int ObjectRef::l_set_sky(lua_State *L)
bool clouds = true;
if (lua_isboolean(L, 5))
- clouds = lua_toboolean(L, 5);
+ clouds = readParam<bool>(L, 5);
getServer(L)->setSky(player, bgcolor, type, params, clouds);
lua_pushboolean(L, true);