Skip to content

Commit

Permalink
Add minetest.get_server_uptime() function to Lua API (#4702)
Browse files Browse the repository at this point in the history
Add minetest.get_server_uptime() function to Lua API
  • Loading branch information
Bremaweb authored and sofar committed Nov 2, 2016
1 parent 7607b0a commit bf315c0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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("")`)
Expand Down
10 changes: 10 additions & 0 deletions src/script/lua_api/l_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions src/script/lua_api/l_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit bf315c0

Please sign in to comment.