aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_base.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2018-06-04 22:38:07 +0200
committerGitHub <noreply@github.com>2018-06-04 22:38:07 +0200
commit180e551c56ec7229a15bfd9ce7339bc9881e1df6 (patch)
tree6425b85a713a8805ce42d5987cb8609c5aeb3d5b /src/script/lua_api/l_base.cpp
parent86b19f284990304f5c8322040f277138333a3697 (diff)
downloadminetest-180e551c56ec7229a15bfd9ce7339bc9881e1df6.tar.gz
minetest-180e551c56ec7229a15bfd9ce7339bc9881e1df6.tar.bz2
minetest-180e551c56ec7229a15bfd9ce7339bc9881e1df6.zip
Modernize lua read (part 1): C++ templating insurance (#7394)
* Modernize lua read (part 1): C++ templating assurance Implement the float reader
Diffstat (limited to 'src/script/lua_api/l_base.cpp')
-rw-r--r--src/script/lua_api/l_base.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp
index e62aa2368..052f661bb 100644
--- a/src/script/lua_api/l_base.cpp
+++ b/src/script/lua_api/l_base.cpp
@@ -90,3 +90,15 @@ bool ModApiBase::isNaN(lua_State *L, int idx)
{
return lua_type(L, idx) == LUA_TNUMBER && std::isnan(lua_tonumber(L, idx));
}
+
+/*
+ * Read template functions
+ */
+template<>
+float ModApiBase::readParam(lua_State *L, int index)
+{
+ if (isNaN(L, index))
+ throw LuaError("NaN value is not allowed.");
+
+ return (float) luaL_checknumber(L, index);
+}