From eef62c82a2e58700fc1216b0b8c03e421bc77995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Blot?= Date: Sat, 30 Jun 2018 17:11:38 +0200 Subject: 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 --- src/script/lua_api/l_server.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/script/lua_api/l_server.cpp') 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(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(L, 2)); else - { - message = "Kicked."; - } + message.append("."); RemotePlayer *player = dynamic_cast(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(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(L, -1, ""); + if (current_mod.empty()) { lua_pop(L, 1); lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str()); } -- cgit v1.2.3