1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-12-21 23:28:48 -05:00

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

Add minetest.get_server_uptime() function to Lua API
This commit is contained in:
Brandon 2016-11-02 11:36:58 -05:00 committed by Auke Kok
parent 7607b0ac20
commit bf315c05f1
4 changed files with 15 additions and 0 deletions

View File

@ -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("")`)

View File

@ -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);

View File

@ -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);

View File

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