aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-12-09 00:34:39 +0000
committerMatthew Wild <mwild1@gmail.com>2009-12-09 00:34:39 +0000
commit5435cbb46fc3456a32fe7527c42e6c7419ceccc1 (patch)
tree175e0ee9b0a8f5c35e1825ba6991424c0115eff5
parent890f155ec2f62c0512de28c16c86c2660b129e08 (diff)
downloadluaevent-prosody-5435cbb46fc3456a32fe7527c42e6c7419ceccc1.tar.gz
luaevent-prosody-5435cbb46fc3456a32fe7527c42e6c7419ceccc1.zip
base:addevent(): Accept integer as fd parameter
-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;
}