From 180e551c56ec7229a15bfd9ce7339bc9881e1df6 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Mon, 4 Jun 2018 22:38:07 +0200 Subject: Modernize lua read (part 1): C++ templating insurance (#7394) * Modernize lua read (part 1): C++ templating assurance Implement the float reader --- src/script/lua_api/l_base.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/script/lua_api/l_base.cpp') 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); +} -- cgit v1.2.3