aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-10-28 12:45:38 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-10-28 12:47:11 +0200
commit557a39c6c8c1a010a8d8e61507f06bfc9dfb119b (patch)
treeb775cb5ee25c3fca98eefea4fb542f51ecdfa46a
parent745e758394e8b6e6118c920b79d333c73f5470ea (diff)
downloadxK-557a39c6c8c1a010a8d8e61507f06bfc9dfb119b.tar.gz
xK-557a39c6c8c1a010a8d8e61507f06bfc9dfb119b.tar.xz
xK-557a39c6c8c1a010a8d8e61507f06bfc9dfb119b.zip
degesch: export server state as a string to Lua
-rw-r--r--degesch.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/degesch.c b/degesch.c
index 828857f..c604e83 100644
--- a/degesch.c
+++ b/degesch.c
@@ -8755,6 +8755,23 @@ lua_server_gc (lua_State *L)
}
static int
+lua_server_get_state (lua_State *L)
+{
+ struct lua_weak *wrapper = lua_weak_deref (L, &lua_server_info);
+ struct server *server = wrapper->object;
+ switch (server->state)
+ {
+ case IRC_DISCONNECTED: lua_pushstring (L, "disconnected"); break;
+ case IRC_CONNECTING: lua_pushstring (L, "connecting"); break;
+ case IRC_CONNECTED: lua_pushstring (L, "connected"); break;
+ case IRC_REGISTERED: lua_pushstring (L, "registered"); break;
+ case IRC_CLOSING: lua_pushstring (L, "closing"); break;
+ case IRC_HALF_CLOSED: lua_pushstring (L, "half_closed"); break;
+ }
+ return 1;
+}
+
+static int
lua_server_send (lua_State *L)
{
struct lua_weak *wrapper = lua_weak_deref (L, &lua_server_info);
@@ -8766,6 +8783,7 @@ lua_server_send (lua_State *L)
static luaL_Reg lua_server_table[] =
{
{ "__gc", lua_server_gc },
+ { "get_state", lua_server_get_state },
{ "send", lua_server_send },
{ NULL, NULL }
};