Skip to content
Permalink
Browse files

Add minetest.get_server_uptime() function to Lua API (#4702)

Add minetest.get_server_uptime() function to Lua API
  • Loading branch information...
Bremaweb authored and sofar committed Nov 2, 2016
1 parent 7607b0a commit bf315c05f17549d37d7b4c4bd7938df0b5b32c5a
Showing with 15 additions and 0 deletions.
  1. +1 −0 doc/lua_api.txt
  2. +10 −0 src/script/lua_api/l_server.cpp
  3. +3 −0 src/script/lua_api/l_server.h
  4. +1 −0 src/server.h
@@ -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("")`)
@@ -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);

@@ -30,6 +30,9 @@ class ModApiServer : public ModApiBase {
// 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);

@@ -216,6 +216,7 @@ class Server : public con::PeerHandler, public MapEventReceiver,

// 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; }

0 comments on commit bf315c0

Please sign in to comment.
You can’t perform that action at this time.