aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/luaevent.c20
1 files changed, 12 insertions, 8 deletions
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;
}