diff options
author | Brandon <brandon@bremaweb.com> | 2016-11-02 11:36:58 -0500 |
---|---|---|
committer | Auke Kok <sofar+github@foo-projects.org> | 2016-11-02 09:36:58 -0700 |
commit | bf315c05f17549d37d7b4c4bd7938df0b5b32c5a (patch) | |
tree | c04f306861d9cee09b0e108e46a6036763526e0c | |
parent | 7607b0ac2065a50a9b68b22909ab40738f2d08e8 (diff) | |
download | minetest-bf315c05f17549d37d7b4c4bd7938df0b5b32c5a.tar.gz minetest-bf315c05f17549d37d7b4c4bd7938df0b5b32c5a.tar.bz2 minetest-bf315c05f17549d37d7b4c4bd7938df0b5b32c5a.zip |
Add minetest.get_server_uptime() function to Lua API (#4702)
Add minetest.get_server_uptime() function to Lua API
-rw-r--r-- | doc/lua_api.txt | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_server.cpp | 10 | ||||
-rw-r--r-- | src/script/lua_api/l_server.h | 3 | ||||
-rw-r--r-- | src/server.h | 1 |
4 files changed, 15 insertions, 0 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 497864fac..119e69f6f 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -2448,6 +2448,7 @@ These functions return the leftover itemstack. * `minetest.request_shutdown([message],[reconnect])`: request for server shutdown. Will display `message` to clients, and `reconnect` == true displays a reconnect button. * `minetest.get_server_status()`: returns server status string +* `minetest.get_server_uptime()`: returns the server uptime in seconds ### Bans * `minetest.get_ban_list()`: returns the ban list (same as `minetest.get_ban_description("")`) diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 95e5da07f..b6d44e0ff 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -45,6 +45,15 @@ int ModApiServer::l_get_server_status(lua_State *L) return 1; } +// get_server_uptime() +int ModApiServer::l_get_server_uptime(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + lua_pushnumber(L, getServer(L)->getUptime()); + return 1; +} + + // print(text) int ModApiServer::l_print(lua_State *L) { @@ -507,6 +516,7 @@ void ModApiServer::Initialize(lua_State *L, int top) { API_FCT(request_shutdown); API_FCT(get_server_status); + API_FCT(get_server_uptime); API_FCT(get_worldpath); API_FCT(is_singleplayer); diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h index 06a5ddc24..1ad46d440 100644 --- a/src/script/lua_api/l_server.h +++ b/src/script/lua_api/l_server.h @@ -30,6 +30,9 @@ private: // get_server_status() static int l_get_server_status(lua_State *L); + // get_server_uptime() + static int l_get_server_uptime(lua_State *L); + // get_worldpath() static int l_get_worldpath(lua_State *L); diff --git a/src/server.h b/src/server.h index 5fc2a9133..f8b3ec106 100644 --- a/src/server.h +++ b/src/server.h @@ -216,6 +216,7 @@ public: // Connection must be locked when called std::wstring getStatusString(); + inline double getUptime() const { return m_uptime.m_value; } // read shutdown state inline bool getShutdownRequested() const { return m_shutdown_requested; } |