summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_util.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2018-06-30 17:11:38 +0200
committerGitHub <noreply@github.com>2018-06-30 17:11:38 +0200
commiteef62c82a2e58700fc1216b0b8c03e421bc77995 (patch)
tree4c49e659069036cb53d69535dc33d33f29d963f4 /src/script/lua_api/l_util.cpp
parent227c71eb76e019873b30e2d3893b68307d51d58f (diff)
downloadminetest-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_util.cpp')
-rw-r--r--src/script/lua_api/l_util.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index b25697611..a58c3a196 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -135,7 +135,7 @@ int ModApiUtil::l_write_json(lua_State *L)
bool styled = false;
if (!lua_isnone(L, 2)) {
- styled = lua_toboolean(L, 2);
+ styled = readParam<bool>(L, 2);
lua_pop(L, 1);
}
@@ -231,7 +231,7 @@ int ModApiUtil::l_is_yes(lua_State *L)
lua_getglobal(L, "tostring"); // function to be called
lua_pushvalue(L, 1); // 1st argument
lua_call(L, 1, 1); // execute function
- std::string str(lua_tostring(L, -1)); // get result
+ std::string str = readParam<std::string>(L, -1); // get result
lua_pop(L, 1);
bool yes = is_yes(str);
@@ -342,7 +342,7 @@ int ModApiUtil::l_get_dir_list(lua_State *L)
NO_MAP_LOCK_REQUIRED;
const char *path = luaL_checkstring(L, 1);
bool list_all = !lua_isboolean(L, 2); // if its not a boolean list all
- bool list_dirs = lua_toboolean(L, 2); // true: list dirs, false: list files
+ bool list_dirs = readParam<bool>(L, 2); // true: list dirs, false: list files
CHECK_SECURE_PATH(L, path, false);
@@ -410,7 +410,7 @@ int ModApiUtil::l_request_insecure_environment(lua_State *L)
}
// Check secure.trusted_mods
- const char *mod_name = lua_tostring(L, -1);
+ std::string mod_name = readParam<std::string>(L, -1);
std::string trusted_mods = g_settings->get("secure.trusted_mods");
trusted_mods.erase(std::remove_if(trusted_mods.begin(),
trusted_mods.end(), static_cast<int(*)(int)>(&std::isspace)),
@@ -451,7 +451,7 @@ int ModApiUtil::l_sha1(lua_State *L)
NO_MAP_LOCK_REQUIRED;
size_t size;
const char *data = luaL_checklstring(L, 1, &size);
- bool hex = !lua_isboolean(L, 2) || !lua_toboolean(L, 2);
+ bool hex = !lua_isboolean(L, 2) || !readParam<bool>(L, 2);
// Compute actual checksum of data
std::string data_sha1;