summaryrefslogtreecommitdiff
path: root/src/script/common/helper.cpp
diff options
context:
space:
mode:
authorZughy <63455151+Zughy@users.noreply.github.com>2020-11-04 21:43:18 +0100
committerGitHub <noreply@github.com>2020-11-04 21:43:18 +0100
commit72b93ec0d75e97ec343e5b936b858d686580677d (patch)
treef02050352671a695a3eac30a0cc24be0bdd02584 /src/script/common/helper.cpp
parent39213bd00a8d00861616d94a29823cb2214f742e (diff)
downloadminetest-72b93ec0d75e97ec343e5b936b858d686580677d.tar.gz
minetest-72b93ec0d75e97ec343e5b936b858d686580677d.tar.bz2
minetest-72b93ec0d75e97ec343e5b936b858d686580677d.zip
Fix ObjectRef errors due to lua_isnil() (#10564)
Treat 'none' values as 'nil'
Diffstat (limited to 'src/script/common/helper.cpp')
-rw-r--r--src/script/common/helper.cpp44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/script/common/helper.cpp b/src/script/common/helper.cpp
index f53a2b7e8..488144790 100644
--- a/src/script/common/helper.cpp
+++ b/src/script/common/helper.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cmath>
#include <sstream>
#include <irr_v2d.h>
+#include <irr_v3d.h>
#include "c_types.h"
#include "c_internal.h"
@@ -54,17 +55,14 @@ template <> bool LuaHelper::readParam(lua_State *L, int index)
return lua_toboolean(L, index) != 0;
}
-template <> bool LuaHelper::readParam(lua_State *L, int index, const bool &default_value)
+template <> s16 LuaHelper::readParam(lua_State *L, int index)
{
- if (lua_isnil(L, index))
- return default_value;
-
- return lua_toboolean(L, index) != 0;
+ return lua_tonumber(L, index);
}
-template <> s16 LuaHelper::readParam(lua_State *L, int index)
+template <> int LuaHelper::readParam(lua_State *L, int index)
{
- return lua_tonumber(L, index);
+ return luaL_checkint(L, index);
}
template <> float LuaHelper::readParam(lua_State *L, int index)
@@ -105,6 +103,25 @@ template <> v2f LuaHelper::readParam(lua_State *L, int index)
return p;
}
+template <> v3f LuaHelper::readParam(lua_State *L, int index)
+{
+ v3f p;
+ CHECK_POS_TAB(index);
+ lua_getfield(L, index, "x");
+ CHECK_POS_COORD("x");
+ p.X = readParam<float>(L, -1);
+ lua_pop(L, 1);
+ lua_getfield(L, index, "y");
+ CHECK_POS_COORD("y");
+ p.Y = readParam<float>(L, -1);
+ lua_pop(L, 1);
+ lua_getfield(L, index, "z");
+ CHECK_POS_COORD("z");
+ p.Z = readParam<float>(L, -1);
+ lua_pop(L, 1);
+ return p;
+}
+
template <> std::string LuaHelper::readParam(lua_State *L, int index)
{
size_t length;
@@ -113,16 +130,3 @@ template <> std::string LuaHelper::readParam(lua_State *L, int index)
result.assign(str, length);
return result;
}
-
-template <>
-std::string LuaHelper::readParam(
- lua_State *L, int index, const std::string &default_value)
-{
- std::string result;
- const char *str = lua_tostring(L, index);
- if (str)
- result.append(str);
- else
- result = default_value;
- return result;
-}