diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-06-30 17:11:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-30 17:11:38 +0200 |
commit | eef62c82a2e58700fc1216b0b8c03e421bc77995 (patch) | |
tree | 4c49e659069036cb53d69535dc33d33f29d963f4 /src/script/lua_api/l_base.cpp | |
parent | 227c71eb76e019873b30e2d3893b68307d51d58f (diff) | |
download | minetest-eef62c82a2e58700fc1216b0b8c03e421bc77995.tar.gz minetest-eef62c82a2e58700fc1216b0b8c03e421bc77995.tar.bz2 minetest-eef62c82a2e58700fc1216b0b8c03e421bc77995.zip |
Modernize lua read (part 2 & 3): C++ templating assurance (#7410)
* Modernize lua read (part 2 & 3): C++ templating assurance
Implement the boolean reader
Implement the string reader
Also remove unused & unimplemented script_error_handler
Add a reader with default value
Diffstat (limited to 'src/script/lua_api/l_base.cpp')
-rw-r--r-- | src/script/lua_api/l_base.cpp | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/src/script/lua_api/l_base.cpp b/src/script/lua_api/l_base.cpp index 052f661bb..b401db05a 100644 --- a/src/script/lua_api/l_base.cpp +++ b/src/script/lua_api/l_base.cpp @@ -63,8 +63,8 @@ GUIEngine *ModApiBase::getGuiEngine(lua_State *L) std::string ModApiBase::getCurrentModPath(lua_State *L) { lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME); - const char *current_mod_name = lua_tostring(L, -1); - if (!current_mod_name) + std::string current_mod_name = readParam<std::string>(L, -1, ""); + if (current_mod_name.empty()) return "."; const ModSpec *mod = getServer(L)->getModSpec(current_mod_name); @@ -85,20 +85,3 @@ 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)); -} - -/* - * 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); -} |