mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-11 17:51:04 +00:00
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
This commit is contained in:
parent
227c71eb76
commit
eef62c82a2
35 changed files with 247 additions and 154 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue