diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index 4055ac24d4..042f231988 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -1346,6 +1346,15 @@ Server class :returns: A :ref:`server_class` which indicates the tracked server or nil if the server doesn't track another one. +.. js:function:: Server.get_trackers(sv) + + Check if the current server is being tracked by other servers. + + :param class_server sv: A :ref:`server_class` which indicates the manipulated + server. + :returns: An array of :ref:`server_class` which indicates the tracking + servers (might be empty) + .. js:function:: Server.event_sub(sv, event_types, func) Register a function that will be called on specific server events. diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index 931b609706..308e1d8219 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -1430,6 +1430,30 @@ int hlua_server_tracking(lua_State *L) return 1; } +/* returns an array of servers tracking the current server */ +int hlua_server_get_trackers(lua_State *L) +{ + struct server *sv; + struct server *cur_tracker; + int index; + + sv = hlua_check_server(L, 1); + if (sv == NULL) { + return 0; + } + + lua_newtable(L); + cur_tracker = sv->trackers; + for (index = 1; cur_tracker; cur_tracker = cur_tracker->tracknext, index++) { + if (!lua_checkstack(L, 5)) + luaL_error(L, "Lua out of memory error."); + hlua_fcn_new_server(L, cur_tracker); + /* array index starts at 1 in Lua */ + lua_rawseti(L, -2, index); + } + return 1; +} + /* hlua_event_sub wrapper for per-server subscription: * * hlua_event_sub() is called with sv->e_subs subscription list and @@ -1493,6 +1517,7 @@ int hlua_fcn_new_server(lua_State *L, struct server *srv) hlua_class_function(L, "agent_force_up", hlua_server_agent_force_up); hlua_class_function(L, "agent_force_down", hlua_server_agent_force_down); hlua_class_function(L, "tracking", hlua_server_tracking); + hlua_class_function(L, "get_trackers", hlua_server_get_trackers); hlua_class_function(L, "event_sub", hlua_server_event_sub); return 1;