lua/uloop: fd_add() better args checking
Actually check for flags being valid, instead of simply ignoring the call if flags was zero. Use standard lua checks for the function argument, so you can get a normal "argument #2 was invalid, expected function, got xxx" instead of the vague, "invalid arg list" Signed-off-by: Karl Palsson <karlp@etactica.com>
This commit is contained in:
parent
e85cb73976
commit
161c25960b
1 changed files with 7 additions and 11 deletions
16
lua/uloop.c
16
lua/uloop.c
|
@ -232,17 +232,14 @@ static int ul_ufd_add(lua_State *L)
|
||||||
int ref;
|
int ref;
|
||||||
int fd_ref;
|
int fd_ref;
|
||||||
|
|
||||||
if (lua_isnumber(L, -1)) {
|
flags = luaL_checkinteger(L, -1);
|
||||||
flags = lua_tointeger(L, -1);
|
if (!flags) {
|
||||||
lua_pop(L, 1);
|
lua_pushstring(L, "flags cannot be zero");
|
||||||
}
|
|
||||||
|
|
||||||
if (!lua_isfunction(L, -1)) {
|
|
||||||
lua_pushstring(L, "invalid arg list");
|
|
||||||
lua_error(L);
|
lua_error(L);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
luaL_checktype(L, -1, LUA_TFUNCTION);
|
||||||
|
|
||||||
fd = get_sock_fd(L, -2);
|
fd = get_sock_fd(L, -2);
|
||||||
|
|
||||||
|
@ -261,7 +258,6 @@ static int ul_ufd_add(lua_State *L)
|
||||||
ufd->fd.fd = fd;
|
ufd->fd.fd = fd;
|
||||||
ufd->fd_r = fd_ref;
|
ufd->fd_r = fd_ref;
|
||||||
ufd->fd.cb = ul_ufd_cb;
|
ufd->fd.cb = ul_ufd_cb;
|
||||||
if (flags)
|
|
||||||
uloop_fd_add(&ufd->fd, flags);
|
uloop_fd_add(&ufd->fd, flags);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue