From eef62c82a2e58700fc1216b0b8c03e421bc77995 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Sat, 30 Jun 2018 17:11:38 +0200 Subject: 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 --- src/script/lua_api/l_env.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/script/lua_api/l_env.cpp') diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 246732a17..4944968da 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -165,10 +165,10 @@ int LuaRaycast::create_object(lua_State *L) v3f pos1 = checkFloatPos(L, 1); v3f pos2 = checkFloatPos(L, 2); if (lua_isboolean(L, 3)) { - objects = lua_toboolean(L, 3); + objects = readParam(L, 3); } if (lua_isboolean(L, 4)) { - liquids = lua_toboolean(L, 4); + liquids = readParam(L, 4); } LuaRaycast *o = new LuaRaycast(core::line3d(pos1, pos2), @@ -757,15 +757,15 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) while (lua_next(L, 3) != 0) { // key at index -2 and value at index -1 luaL_checktype(L, -1, LUA_TSTRING); - ndef->getIds(lua_tostring(L, -1), filter); + ndef->getIds(readParam(L, -1), filter); // removes value, keeps key for next iteration lua_pop(L, 1); } } else if (lua_isstring(L, 3)) { - ndef->getIds(lua_tostring(L, 3), filter); + ndef->getIds(readParam(L, 3), filter); } - int start_radius = (lua_toboolean(L, 4)) ? 0 : 1; + int start_radius = (lua_isboolean(L, 4) && readParam(L, 4)) ? 0 : 1; #ifndef SERVER // Client API limitations @@ -815,12 +815,12 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) while (lua_next(L, 3) != 0) { // key at index -2 and value at index -1 luaL_checktype(L, -1, LUA_TSTRING); - ndef->getIds(lua_tostring(L, -1), filter); + ndef->getIds(readParam(L, -1), filter); // removes value, keeps key for next iteration lua_pop(L, 1); } } else if (lua_isstring(L, 3)) { - ndef->getIds(lua_tostring(L, 3), filter); + ndef->getIds(readParam(L, 3), filter); } std::vector individual_count; @@ -884,12 +884,12 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) while (lua_next(L, 3) != 0) { // key at index -2 and value at index -1 luaL_checktype(L, -1, LUA_TSTRING); - ndef->getIds(lua_tostring(L, -1), filter); + ndef->getIds(readParam(L, -1), filter); // removes value, keeps key for next iteration lua_pop(L, 1); } } else if (lua_isstring(L, 3)) { - ndef->getIds(lua_tostring(L, 3), filter); + ndef->getIds(readParam(L, 3), filter); } lua_newtable(L); -- cgit v1.2.3