* available.
*/
__LJMP static inline void hlua_class_const_int(lua_State *L, const char *name,
- unsigned int value)
+ int value)
{
if (!lua_checkstack(L, 2))
WILL_LJMP(luaL_error(L, "full stack"));
lua_pushstring(L, name);
- lua_pushunsigned(L, value);
+ lua_pushinteger(L, value);
lua_settable(L, -3);
}
__LJMP static inline void hlua_class_const_str(lua_State *L, const char *name,
case ARGT_UINT:
case ARGT_TIME:
case ARGT_SIZE:
- lua_pushunsigned(L, arg->data.sint);
+ lua_pushinteger(L, arg->data.sint);
break;
case ARGT_STR:
{
switch (smp->type) {
case SMP_T_SINT:
- lua_pushinteger(L, smp->data.sint);
- break;
-
case SMP_T_BOOL:
case SMP_T_UINT:
- lua_pushunsigned(L, smp->data.uint);
+ lua_pushinteger(L, smp->data.sint);
break;
case SMP_T_BIN:
* returned with a timeout and permit to set some flags
*/
__LJMP void hlua_yieldk(lua_State *L, int nresults, int ctx,
- lua_CFunction k, int timeout, unsigned int flags)
+ lua_KFunction k, int timeout, unsigned int flags)
{
struct hlua *hlua = hlua_gethlua(L);
*/
#define HLSR_READ_LINE (-1)
#define HLSR_READ_ALL (-2)
-__LJMP static int hlua_socket_receive_yield(struct lua_State *L)
+__LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua_KContext ctx)
{
struct hlua_socket *socket = MAY_LJMP(hlua_checksocket(L, 1));
int wanted = lua_tointeger(L, 2);
luaL_addlstring(&socket->b, pattern, len);
}
- return __LJMP(hlua_socket_receive_yield(L));
+ return __LJMP(hlua_socket_receive_yield(L, 0, 0));
}
/* Write the Lua input string in the output buffer.
* This fucntion returns a yield if no space are available.
*/
-static int hlua_socket_write_yield(struct lua_State *L)
+static int hlua_socket_write_yield(struct lua_State *L,int status, lua_KContext ctx)
{
struct hlua_socket *socket;
struct hlua *hlua = hlua_gethlua(L);
/* Get object */
socket = MAY_LJMP(hlua_checksocket(L, 1));
buf = MAY_LJMP(luaL_checklstring(L, 2, &buf_len));
- sent = MAY_LJMP(luaL_checkunsigned(L, 3));
+ sent = MAY_LJMP(luaL_checkinteger(L, 3));
/* Check for connection close. */
if (!socket->s || channel_output_closed(socket->s->req)) {
if (len <= 0) {
MAY_LJMP(hlua_socket_close(L));
lua_pop(L, 1);
- lua_pushunsigned(L, -1);
+ lua_pushinteger(L, -1);
return 1;
}
/* Update length sent. */
lua_pop(L, 1);
- lua_pushunsigned(L, sent + len);
+ lua_pushinteger(L, sent + len);
/* All the data buffer is sent ? */
if (sent + len >= buf_len)
/* Check bth i and j. */
if (i > j) {
- lua_pushunsigned(L, 0);
+ lua_pushinteger(L, 0);
return 1;
}
if (i == 0 && j == 0) {
- lua_pushunsigned(L, 0);
+ lua_pushinteger(L, 0);
return 1;
}
if (i == 0)
lua_pushlstring(L, buf, buf_len);
/* This unsigned is used to remember the amount of sent data. */
- lua_pushunsigned(L, 0);
+ lua_pushinteger(L, 0);
- return MAY_LJMP(hlua_socket_write_yield(L));
+ return MAY_LJMP(hlua_socket_write_yield(L, 0, 0));
}
#define SOCKET_INFO_EXPANDED_FORM "[0000:0000:0000:0000:0000:0000:0000:0000]:12345"
.release = hlua_socket_release,
};
-__LJMP static int hlua_socket_connect_yield(struct lua_State *L)
+__LJMP static int hlua_socket_connect_yield(struct lua_State *L, int status, lua_KContext ctx)
{
struct hlua_socket *socket = MAY_LJMP(hlua_checksocket(L, 1));
struct hlua *hlua = hlua_gethlua(L);
__LJMP static int hlua_socket_connect(struct lua_State *L)
{
struct hlua_socket *socket;
- unsigned int port;
+ int port;
const char *ip;
struct connection *conn;
/* Get args. */
socket = MAY_LJMP(hlua_checksocket(L, 1));
ip = MAY_LJMP(luaL_checkstring(L, 2));
- port = MAY_LJMP(luaL_checkunsigned(L, 3));
+ port = MAY_LJMP(luaL_checkinteger(L, 3));
conn = si_alloc_conn(socket->s->req->cons, 0);
if (!conn)
__LJMP static int hlua_socket_settimeout(struct lua_State *L)
{
struct hlua_socket *socket;
- unsigned int tmout;
+ int tmout;
MAY_LJMP(check_args(L, 2, "settimeout"));
socket = MAY_LJMP(hlua_checksocket(L, 1));
- tmout = MAY_LJMP(luaL_checkunsigned(L, 2)) * 1000;
+ tmout = MAY_LJMP(luaL_checkinteger(L, 2)) * 1000;
socket->s->req->rto = tmout;
socket->s->req->wto = tmout;
/* "_hlua_channel_dup" wrapper. If no data are available, it returns
* a yield. This function keep the data in the buffer.
*/
-__LJMP static int hlua_channel_dup(lua_State *L)
+__LJMP static int hlua_channel_dup_yield(lua_State *L, int status, lua_KContext ctx)
{
struct hlua_channel *chn;
- MAY_LJMP(check_args(L, 1, "dup"));
-
chn = MAY_LJMP(hlua_checkchannel(L, 1));
if (_hlua_channel_dup(chn, L) == 0)
- WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_dup, TICK_ETERNITY, 0));
+ WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_dup_yield, TICK_ETERNITY, 0));
return 1;
}
+/* Check arguments for the function "hlua_channel_dup_yield". */
+__LJMP static int hlua_channel_dup(lua_State *L)
+{
+ MAY_LJMP(check_args(L, 1, "dup"));
+ MAY_LJMP(hlua_checkchannel(L, 1));
+ return MAY_LJMP(hlua_channel_dup_yield(L, 0, 0));
+}
+
/* "_hlua_channel_dup" wrapper. If no data are available, it returns
* a yield. This function consumes the data in the buffer. It returns
* a string containing the data or a nil pointer if no data are available
* and the channel is closed.
*/
-__LJMP static int hlua_channel_get(lua_State *L)
+__LJMP static int hlua_channel_get_yield(lua_State *L, int status, lua_KContext ctx)
{
struct hlua_channel *chn;
int ret;
- MAY_LJMP(check_args(L, 1, "get"));
-
chn = MAY_LJMP(hlua_checkchannel(L, 1));
+
ret = _hlua_channel_dup(chn, L);
if (unlikely(ret == 0))
- WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_get, TICK_ETERNITY, 0));
+ WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_get_yield, TICK_ETERNITY, 0));
if (unlikely(ret == -1))
return 1;
return 1;
}
+/* Check arguments for the fucntion "hlua_channel_get_yield". */
+__LJMP static int hlua_channel_get(lua_State *L)
+{
+ MAY_LJMP(check_args(L, 1, "get"));
+ MAY_LJMP(hlua_checkchannel(L, 1));
+ return MAY_LJMP(hlua_channel_get_yield(L, 0, 0));
+}
+
/* This functions consumes and returns one line. If the channel is closed,
* and the last data does not contains a final '\n', the data are returned
* without the final '\n'. When no more data are avalaible, it returns nil
* value.
*/
-__LJMP static int hlua_channel_getline(lua_State *L)
+__LJMP static int hlua_channel_getline_yield(lua_State *L, int status, lua_KContext ctx)
{
char *blk1;
char *blk2;
int ret;
luaL_Buffer b;
- MAY_LJMP(check_args(L, 1, "getline"));
chn = MAY_LJMP(hlua_checkchannel(L, 1));
ret = bi_getline_nc(chn->chn, &blk1, &len1, &blk2, &len2);
if (ret == 0)
- WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_getline, TICK_ETERNITY, 0));
+ WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_getline_yield, TICK_ETERNITY, 0));
if (ret == -1) {
lua_pushnil(L);
return 1;
}
+/* Check arguments for the fucntion "hlua_channel_getline_yield". */
+__LJMP static int hlua_channel_getline(lua_State *L)
+{
+ MAY_LJMP(check_args(L, 1, "getline"));
+ MAY_LJMP(hlua_checkchannel(L, 1));
+ return MAY_LJMP(hlua_channel_getline_yield(L, 0, 0));
+}
+
/* This function takes a string as input, and append it at the
* input side of channel. If the data is too big, but a space
* is probably available after sending some data, the function
* channel is closed, it returns -1. otherwise, it returns the
* amount of data writed.
*/
-__LJMP static int _hlua_channel_append(lua_State *L)
+__LJMP static int hlua_channel_append_yield(lua_State *L, int status, lua_KContext ctx)
{
struct hlua_channel *chn = MAY_LJMP(hlua_checkchannel(L, 1));
size_t len;
return 1;
}
if (ret == -1)
- WILL_LJMP(hlua_yieldk(L, 0, 0, _hlua_channel_append, TICK_ETERNITY, 0));
+ WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_append_yield, TICK_ETERNITY, 0));
l += ret;
lua_pop(L, 1);
lua_pushinteger(L, l);
return 1;
}
if (l < len)
- WILL_LJMP(hlua_yieldk(L, 0, 0, _hlua_channel_append, TICK_ETERNITY, 0));
+ WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_append_yield, TICK_ETERNITY, 0));
return 1;
}
-/* just a wrapper of "_hlua_channel_append". It returns the length
+/* just a wrapper of "hlua_channel_append_yield". It returns the length
* of the writed string, or -1 if the channel is closed or if the
* buffer size is too little for the data.
*/
__LJMP static int hlua_channel_append(lua_State *L)
{
+ size_t len;
+
MAY_LJMP(check_args(L, 2, "append"));
+ MAY_LJMP(hlua_checkchannel(L, 1));
+ MAY_LJMP(luaL_checklstring(L, 2, &len));
+ MAY_LJMP(luaL_checkinteger(L, 3));
lua_pushinteger(L, 0);
- return MAY_LJMP(_hlua_channel_append(L));
+ return MAY_LJMP(hlua_channel_append_yield(L, 0, 0));
}
-/* just a wrapper of "_hlua_channel_append". This wrapper starts
+/* just a wrapper of "hlua_channel_append_yield". This wrapper starts
* his process by cleaning the buffer. The result is a replacement
* of the current data. It returns the length of the writed string,
* or -1 if the channel is closed or if the buffer size is too
chn->chn->buf->i = 0;
- return MAY_LJMP(_hlua_channel_append(L));
+ return MAY_LJMP(hlua_channel_append_yield(L, 0, 0));
}
/* Append data in the output side of the buffer. This data is immediatly
* cannot contains the data, the function yield. The function returns -1
* if the channel is closed.
*/
-__LJMP static int _hlua_channel_send(lua_State *L)
+__LJMP static int hlua_channel_send_yield(lua_State *L, int status, lua_KContext ctx)
{
struct hlua_channel *chn = MAY_LJMP(hlua_checkchannel(L, 1));
size_t len;
if (chn->chn->buf->size == 0) {
if (!session_alloc_recv_buffer(chn->s, &chn->chn->buf)) {
chn->chn->prod->flags |= SI_FL_WAIT_ROOM;
- WILL_LJMP(hlua_yieldk(L, 0, 0, _hlua_channel_send, TICK_ETERNITY, 0));
+ WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_channel_send_yield, TICK_ETERNITY, 0));
}
}
MAY_LJMP(check_args(L, 2, "send"));
lua_pushinteger(L, 0);
- return MAY_LJMP(_hlua_channel_send(L));
+ return MAY_LJMP(hlua_channel_send_yield(L, 0, 0));
}
/* This function forward and amount of butes. The data pass from
* The Lua function takes an amount of bytes to be forwarded in
* imput. It returns the number of bytes forwarded.
*/
-__LJMP static int hlua_channel_forward_yield(lua_State *L)
+__LJMP static int hlua_channel_forward_yield(lua_State *L, int status, lua_KContext ctx)
{
struct hlua_channel *chn;
int len;
MAY_LJMP(luaL_checkinteger(L, 2));
lua_pushinteger(L, 0);
- return MAY_LJMP(hlua_channel_forward_yield(L));
+ return MAY_LJMP(hlua_channel_forward_yield(L, 0, 0));
}
/* Just returns the number of bytes available in the input
return 1;
}
-__LJMP static int hlua_sleep_yield(lua_State *L)
+__LJMP static int hlua_sleep_yield(lua_State *L, int status, lua_KContext ctx)
{
int wakeup_ms = lua_tointeger(L, -1);
if (now_ms < wakeup_ms)
MAY_LJMP(check_args(L, 1, "sleep"));
- delay = MAY_LJMP(luaL_checkunsigned(L, 1)) * 1000;
+ delay = MAY_LJMP(luaL_checkinteger(L, 1)) * 1000;
wakeup_ms = tick_add(now_ms, delay);
lua_pushinteger(L, wakeup_ms);
MAY_LJMP(check_args(L, 1, "msleep"));
- delay = MAY_LJMP(luaL_checkunsigned(L, 1));
+ delay = MAY_LJMP(luaL_checkinteger(L, 1));
wakeup_ms = tick_add(now_ms, delay);
lua_pushinteger(L, wakeup_ms);
* the hand at the HAProxy scheduler. It is used when the
* LUA processing consumes a lot of time.
*/
-__LJMP static int hlua_yield_yield(lua_State *L)
+__LJMP static int hlua_yield_yield(lua_State *L, int status, lua_KContext ctx)
{
return 0;
}