summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2018-05-31 22:52:08 +0200
committerGitHub <noreply@github.com>2018-05-31 22:52:08 +0200
commit162ffd7fba9d4e79a29f65686f3efbebaee9cee8 (patch)
treed58d2329f223eb991b4c39c7cfce209c46edc284
parentdf991edaa8617730f4ad15648e9131325a0fe2e8 (diff)
downloadminetest-162ffd7fba9d4e79a29f65686f3efbebaee9cee8.tar.gz
minetest-162ffd7fba9d4e79a29f65686f3efbebaee9cee8.tar.bz2
minetest-162ffd7fba9d4e79a29f65686f3efbebaee9cee8.zip
Fix isNan on setYaw Lua call (#7380)
* Fix isNan on setYaw Lua call
-rw-r--r--doc/client_lua_api.txt2
-rw-r--r--doc/lua_api.txt2
-rw-r--r--src/script/lua_api/l_base.cpp8
-rw-r--r--src/script/lua_api/l_base.h2
-rw-r--r--src/script/lua_api/l_object.cpp3
-rw-r--r--src/script/lua_api/l_util.cpp11
-rw-r--r--src/script/lua_api/l_util.h3
7 files changed, 30 insertions, 1 deletions
diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt
index 5651898aa..bdefa3af5 100644
--- a/doc/client_lua_api.txt
+++ b/doc/client_lua_api.txt
@@ -609,6 +609,8 @@ Helper functions
* Converts a string representing an area box into two positions
* `minetest.is_yes(arg)`
* returns whether `arg` can be interpreted as yes
+* `minetest.is_nan(arg)`
+ * returns true true when the passed number represents NaN.
* `table.copy(table)`: returns a table
* returns a deep copy of `table`
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 13ba492a7..12008d0e8 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -2541,6 +2541,8 @@ Helper functions
in formspecs.
* `minetest.is_yes(arg)`
* returns true if passed 'y', 'yes', 'true' or a number that isn't zero.
+* `minetest.is_nan(arg)`
+ * returns true when the passed number represents NaN.
* `minetest.get_us_time()`
* returns time with microsecond precision. May not return wall time.
* `table.copy(table)`: returns a table
diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp
index 8ab0a20b6..e62aa2368 100644
--- a/src/script/lua_api/l_base.cpp
+++ b/src/script/lua_api/l_base.cpp
@@ -21,7 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_internal.h"
#include "cpp_api/s_base.h"
#include "content/mods.h"
-#include <server.h>
+#include "server.h"
+#include <cmath>
ScriptApiBase *ModApiBase::getScriptApiBase(lua_State *L)
{
@@ -84,3 +85,8 @@ bool ModApiBase::registerFunction(lua_State *L, const char *name,
return true;
}
+
+bool ModApiBase::isNaN(lua_State *L, int idx)
+{
+ return lua_type(L, idx) == LUA_TNUMBER && std::isnan(lua_tonumber(L, idx));
+}
diff --git a/src/script/lua_api/l_base.h b/src/script/lua_api/l_base.h
index 0a75b4c1a..20aa4cc09 100644
--- a/src/script/lua_api/l_base.h
+++ b/src/script/lua_api/l_base.h
@@ -69,4 +69,6 @@ public:
const char* name,
lua_CFunction func,
int top);
+
+ static bool isNaN(lua_State *L, int idx);
};
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index b3c3a55bf..8377f95c8 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -895,6 +895,9 @@ int ObjectRef::l_set_yaw(lua_State *L)
ObjectRef *ref = checkobject(L, 1);
LuaEntitySAO *co = getluaobject(ref);
if (co == NULL) return 0;
+ if (isNaN(L, 2))
+ throw LuaError("ObjectRef::set_yaw: NaN value is not allowed.");
+
float yaw = luaL_checknumber(L, 2) * core::RADTODEG;
// Do it
co->setYaw(yaw);
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index 501261dd7..c1b760941 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -240,6 +240,15 @@ int ModApiUtil::l_is_yes(lua_State *L)
return 1;
}
+// is_nan(arg)
+int ModApiUtil::l_is_nan(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ lua_pushboolean(L, isNaN(L, 1));
+ return 1;
+}
+
// get_builtin_path()
int ModApiUtil::l_get_builtin_path(lua_State *L)
{
@@ -481,6 +490,7 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(get_password_hash);
API_FCT(is_yes);
+ API_FCT(is_nan);
API_FCT(get_builtin_path);
@@ -513,6 +523,7 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
API_FCT(write_json);
API_FCT(is_yes);
+ API_FCT(is_nan);
API_FCT(compress);
API_FCT(decompress);
diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h
index 4392a4339..5697aab15 100644
--- a/src/script/lua_api/l_util.h
+++ b/src/script/lua_api/l_util.h
@@ -65,6 +65,9 @@ private:
// is_yes(arg)
static int l_is_yes(lua_State *L);
+ // is_nan(arg)
+ static int l_is_nan(lua_State *L);
+
// get_builtin_path()
static int l_get_builtin_path(lua_State *L);