Add an optional port parameter, which can be either a number or a
string (to support '+' and '-' for port mapping).

This fixes issue #586.
---
 doc/lua-api/index.rst | 2 +-
 src/hlua_fcn.c        | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst
index 9a578ee29..f3e5cb786 100644
--- a/doc/lua-api/index.rst
+++ b/doc/lua-api/index.rst
@@ -976,7 +976,7 @@ Server class
     server.
   :returns: an integer.
 
-.. js:function:: Server.set_addr(sv, addr)
+.. js:function:: Server.set_addr(sv, addr[, port])
 
   Dynamically change the address of the server. See the management socket
   documentation for more information about the format of the string.
diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c
index a9c7fe507..e6f4d7379 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -1034,13 +1034,18 @@ int hlua_server_set_addr(lua_State *L)
 {
        struct server *srv;
        const char *addr;
+       const char *port;
        const char *err;
 
        srv = hlua_check_server(L, 1);
        addr = luaL_checkstring(L, 2);
+       if (lua_gettop(L) >= 3)
+               port = luaL_checkstring(L, 3);
+       else
+               port = NULL;
 
        HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
-       err = server_parse_addr_change_request(srv, addr, "Lua script");
+       err = update_server_addr_port(srv, addr, port, "Lua script");
        HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
        if (!err)
                lua_pushnil(L);
-- 
2.25.1


Reply via email to