3 Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 bool LuaHelper::isNaN(lua_State *L, int idx)
27 return lua_type(L, idx) == LUA_TNUMBER && std::isnan(lua_tonumber(L, idx));
31 * Read template functions
33 template <> bool LuaHelper::readParam(lua_State *L, int index)
35 return lua_toboolean(L, index) != 0;
38 template <> bool LuaHelper::readParam(lua_State *L, int index, const bool &default_value)
40 if (lua_isnil(L, index))
43 return lua_toboolean(L, index) != 0;
46 template <> float LuaHelper::readParam(lua_State *L, int index)
49 throw LuaError("NaN value is not allowed.");
51 return (float)luaL_checknumber(L, index);
54 template <> std::string LuaHelper::readParam(lua_State *L, int index)
57 const char *str = luaL_checkstring(L, index);
63 std::string LuaHelper::readParam(
64 lua_State *L, int index, const std::string &default_value)
67 const char *str = lua_tostring(L, index);
71 result = default_value;