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_server.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_server.cpp')
-rw-r--r-- | src/script/lua_api/l_server.cpp | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 7eba79565..6017a5475 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -33,7 +33,7 @@ int ModApiServer::l_request_shutdown(lua_State *L) { NO_MAP_LOCK_REQUIRED; const char *msg = lua_tolstring(L, 1, NULL); - bool reconnect = lua_toboolean(L, 2); + bool reconnect = readParam<bool>(L, 2); float seconds_before_shutdown = lua_tonumber(L, 3); getServer(L)->requestShutdown(msg ? msg : "", reconnect, seconds_before_shutdown); return 0; @@ -310,15 +310,11 @@ int ModApiServer::l_kick_player(lua_State *L) { NO_MAP_LOCK_REQUIRED; const char *name = luaL_checkstring(L, 1); - std::string message; + std::string message("Kicked"); if (lua_isstring(L, 2)) - { - message = std::string("Kicked: ") + lua_tostring(L, 2); - } + message.append(": ").append(readParam<std::string>(L, 2)); else - { - message = "Kicked."; - } + message.append("."); RemotePlayer *player = dynamic_cast<ServerEnvironment *>(getEnv(L))->getPlayer(name); if (player == NULL) { @@ -475,7 +471,7 @@ int ModApiServer::l_notify_authentication_modified(lua_State *L) NO_MAP_LOCK_REQUIRED; std::string name; if(lua_isstring(L, 1)) - name = lua_tostring(L, 1); + name = readParam<std::string>(L, 1); getServer(L)->reportPrivsModified(name); return 0; } @@ -485,8 +481,8 @@ int ModApiServer::l_get_last_run_mod(lua_State *L) { NO_MAP_LOCK_REQUIRED; lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME); - const char *current_mod = lua_tostring(L, -1); - if (current_mod == NULL || current_mod[0] == '\0') { + std::string current_mod = readParam<std::string>(L, -1, ""); + if (current_mod.empty()) { lua_pop(L, 1); lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str()); } |