Hi,

This is a small patch about the Lua documentation.
it should be backported in 1.8

Note that the function prototype is compatible with old versions.

Thierry

>From 4feaa411b6cca0b3a57ebe16c13ce056d93eb74a Mon Sep 17 00:00:00 2001
From: Thierry FOURNIER <thierry.fourn...@ozon.io>
Date: Mon, 12 Feb 2018 14:46:54 +0100
Subject: [PATCH] DOC: new prototype for function "register_action()"

This patch should e backported in version 1.8
---
 doc/lua-api/index.rst | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst
index 7fe609f..e7aa425 100644
--- a/doc/lua-api/index.rst
+++ b/doc/lua-api/index.rst
@@ -443,7 +443,7 @@ Core class
   configuration file. Each entry of the proxies array is an object of type
   :ref:`proxy_class`
 
-.. js:function:: core.register_action(name, actions, func)
+.. js:function:: core.register_action(name, actions, func [, nb_args])
 
   **context**: body
 
@@ -455,18 +455,22 @@ Core class
   :param table actions: is a table of string describing the HAProxy actions who
                         want to register to. The expected actions are 'tcp-req',
                         'tcp-res', 'http-req' or 'http-res'.
+  :param integer nb_args: is the expected number of argument for the action.
+                          By default the value is 0.
   :param function func: is the Lua function called to work as converter.
 
   The prototype of the Lua function used as argument is:
 
 .. code-block:: lua
 
-  function(txn)
+  function(txn [, arg1 [, arg2]])
 ..
 
   * **txn** (:ref:`txn_class`): this is a TXN object used for manipulating the
             current request or TCP stream.
 
+  * **argX**: this is argument provided throught the HAProxy configuration file.
+
   Here, an exemple of action registration. the action juste send an 'Hello world'
   in the logs.
 
@@ -488,7 +492,26 @@ Core class
   frontend http_frt
     mode http
     http-request lua.hello-world
+..
+
+  A second example using aruments
+
+.. code-block:: lua
+
+  function hello_world(txn, arg)
+     txn:Info("Hello world for " .. arg)
+  end
+  core.register_action("hello-world", { "tcp-req", "http-req" }, hello_world, 2)
+..
 
+  This example code is used in HAproxy configuration like this:
+
+::
+
+  frontend tcp_frt
+    mode tcp
+    tcp-request content lua.hello-world everybody
+..
 .. js:function:: core.register_converters(name, func)
 
   **context**: body
-- 
2.9.5

Reply via email to