From 397826aedc75584e5a1f6e52a9ae4f2f4c1bd5a5 Mon Sep 17 00:00:00 2001 From: Thierry FOURNIER Date: Wed, 11 Mar 2015 19:39:09 +0100 Subject: [PATCH] MINOR: lua: replace function (req|get)_channel by a variable 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 | 48 ++++++++++++------------------------------------ 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index 479b1c750..25e1a2b01 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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);