base:addevent(): Accept integer as fd parameter

Wed, 09 Dec 2009 00:34:39 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 09 Dec 2009 00:34:39 +0000
changeset 72
adb5fa9ea85a
parent 71
3e56f21e2e28
child 73
e9b909b391c3

base:addevent(): Accept integer as fd parameter

src/luaevent.c file | annotate | diff | comparison | revisions
--- a/src/luaevent.c	Mon Dec 07 22:48:43 2009 +0000
+++ b/src/luaevent.c	Wed Dec 09 00:34:39 2009 +0000
@@ -45,14 +45,18 @@
 
 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;
 }
 

mercurial