From 5435cbb46fc3456a32fe7527c42e6c7419ceccc1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 9 Dec 2009 00:34:39 +0000 Subject: base:addevent(): Accept integer as fd parameter --- src/luaevent.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/luaevent.c b/src/luaevent.c index 8a682df..a8d5f7d 100644 --- a/src/luaevent.c +++ b/src/luaevent.c @@ -45,14 +45,18 @@ static int luaevent_base_gc(lua_State* L) { int getSocketFd(lua_State* L, int idx) { int fd; - luaL_checktype(L, idx, LUA_TUSERDATA); - lua_getfield(L, idx, "getfd"); - if(lua_isnil(L, -1)) - return luaL_error(L, "Socket type missing 'getfd' method"); - lua_pushvalue(L, idx); - lua_call(L, 1, 1); - fd = lua_tointeger(L, -1); - lua_pop(L, 1); + if(lua_isnumber(L, idx)) { + fd = lua_tonumber(L, idx); + } else { + luaL_checktype(L, idx, LUA_TUSERDATA); + lua_getfield(L, idx, "getfd"); + if(lua_isnil(L, -1)) + return luaL_error(L, "Socket type missing 'getfd' method"); + lua_pushvalue(L, idx); + lua_call(L, 1, 1); + fd = lua_tointeger(L, -1); + lua_pop(L, 1); + } return fd; } -- cgit v1.2.3