src/luaevent.c

changeset 72
adb5fa9ea85a
parent 69
da7e8688a2b5
child 75
5a5f46aed0c1
equal deleted inserted replaced
71:3e56f21e2e28 72:adb5fa9ea85a
43 return 0; 43 return 0;
44 } 44 }
45 45
46 int getSocketFd(lua_State* L, int idx) { 46 int getSocketFd(lua_State* L, int idx) {
47 int fd; 47 int fd;
48 luaL_checktype(L, idx, LUA_TUSERDATA); 48 if(lua_isnumber(L, idx)) {
49 lua_getfield(L, idx, "getfd"); 49 fd = lua_tonumber(L, idx);
50 if(lua_isnil(L, -1)) 50 } else {
51 return luaL_error(L, "Socket type missing 'getfd' method"); 51 luaL_checktype(L, idx, LUA_TUSERDATA);
52 lua_pushvalue(L, idx); 52 lua_getfield(L, idx, "getfd");
53 lua_call(L, 1, 1); 53 if(lua_isnil(L, -1))
54 fd = lua_tointeger(L, -1); 54 return luaL_error(L, "Socket type missing 'getfd' method");
55 lua_pop(L, 1); 55 lua_pushvalue(L, idx);
56 lua_call(L, 1, 1);
57 fd = lua_tointeger(L, -1);
58 lua_pop(L, 1);
59 }
56 return fd; 60 return fd;
57 } 61 }
58 62
59 void load_timeval(double time, struct timeval *tv) { 63 void load_timeval(double time, struct timeval *tv) {
60 tv->tv_sec = (int)time; 64 tv->tv_sec = (int)time;

mercurial