]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: replace function (req|get)_channel by a variable
authorThierry FOURNIER <tfournier@exceliance.fr>
Wed, 11 Mar 2015 18:39:09 +0000 (19:39 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 11 Mar 2015 18:55:10 +0000 (19:55 +0100)
To add data in channel, it is necessary to process in two times.
First time, get the channel object, and after send data:

   local req = txn:req_channel()
req:send("data\n")

Now, the function is converted as a variable containing the req
and res aobject. We can process as following:

   txn.req:send("data\n")

src/hlua.c

index 479b1c7506d08213a61fdb9523db715e2ca26d2d..25e1a2b019308e329de08b4497a59e9421116cda 100644 (file)
@@ -2769,6 +2769,18 @@ static int hlua_txn_new(lua_State *L, struct session *s, struct proxy *p, void *
                return 0;
        lua_settable(L, -3);
 
+       /* Create the "req" field that contains the request channel object. */
+       lua_pushstring(L, "req");
+       if (!hlua_channel_new(L, s, s->req))
+               return 0;
+       lua_settable(L, -3);
+
+       /* Create the "res" field that contains the response channel object. */
+       lua_pushstring(L, "res");
+       if (!hlua_channel_new(L, s, s->rep))
+               return 0;
+       lua_settable(L, -3);
+
        /* Pop a class sesison metatable and affect it to the userdata. */
        lua_rawgeti(L, LUA_REGISTRYINDEX, class_txn_ref);
        lua_setmetatable(L, -2);
@@ -2776,40 +2788,6 @@ static int hlua_txn_new(lua_State *L, struct session *s, struct proxy *p, void *
        return 1;
 }
 
-/* This function returns a channel object associated
- * with the request channel. This function never fails,
- * however if the stack is full, it throws an error.
- */
-__LJMP static int hlua_txn_req_channel(lua_State *L)
-{
-       struct hlua_txn *s;
-
-       MAY_LJMP(check_args(L, 1, "req_channel"));
-       s = MAY_LJMP(hlua_checktxn(L, 1));
-
-       if (!hlua_channel_new(L, s->s, s->s->req))
-               WILL_LJMP(luaL_error(L, "full stack"));
-
-       return 1;
-}
-
-/* This function returns a channel object associated
- * with the response channel. This function never fails,
- * however if the stack is full, it throws an error.
- */
-__LJMP static int hlua_txn_res_channel(lua_State *L)
-{
-       struct hlua_txn *s;
-
-       MAY_LJMP(check_args(L, 1, "res_channel"));
-       s = MAY_LJMP(hlua_checktxn(L, 1));
-
-       if (!hlua_channel_new(L, s->s, s->s->rep))
-               WILL_LJMP(luaL_error(L, "full stack"));
-
-       return 1;
-}
-
 /* This function is an Lua binding that send pending data
  * to the client, and close the stream interface.
  */
@@ -4046,8 +4024,6 @@ void hlua_init(void)
        hlua_class_function(gL.T, "get_headers", hlua_session_get_headers);
        hlua_class_function(gL.T, "set_priv",    hlua_set_priv);
        hlua_class_function(gL.T, "get_priv",    hlua_get_priv);
-       hlua_class_function(gL.T, "req_channel", hlua_txn_req_channel);
-       hlua_class_function(gL.T, "res_channel", hlua_txn_res_channel);
        hlua_class_function(gL.T, "close",       hlua_txn_close);
 
        lua_settable(gL.T, -3);