29 if(arg->L) { |
29 if(arg->L) { |
30 lua_State* L = arg->L; |
30 lua_State* L = arg->L; |
31 arg->L = NULL; |
31 arg->L = NULL; |
32 event_del(&arg->ev); |
32 event_del(&arg->ev); |
33 luaL_unref(L, LUA_REGISTRYINDEX, arg->callbackRef); |
33 luaL_unref(L, LUA_REGISTRYINDEX, arg->callbackRef); |
|
34 luaL_unref(L, LUA_REGISTRYINDEX, arg->objectRef); |
34 } |
35 } |
35 } |
36 } |
36 |
37 |
37 static int call_callback_function(lua_State* L, int argCount) { |
38 static int call_callback_function(lua_State* L, int argCount) { |
38 int ret; |
39 int ret; |
45 ret = lua_tointeger(L, -1) | -lua_isnil(L, -1); |
46 ret = lua_tointeger(L, -1) | -lua_isnil(L, -1); |
46 lua_pop(L, 1); |
47 lua_pop(L, 1); |
47 if(ret < 0) { /* Done, no need to setup event */ |
48 if(ret < 0) { /* Done, no need to setup event */ |
48 return -1; |
49 return -1; |
49 } |
50 } |
50 printf("WAITING FOR: %i RED: %i WR:%i\n", ret, EV_READ, EV_WRITE); |
|
51 if(ret != EV_READ && ret != EV_WRITE) { |
51 if(ret != EV_READ && ret != EV_WRITE) { |
52 printf("BAD RET_VAL IN INIT: %i\n", ret); |
52 printf("BAD RET_VAL IN INIT: %i\n", ret); |
53 } |
53 } |
54 return ret; |
54 return ret; |
55 } |
55 } |
78 if(-1 == (ret = call_callback_function(L, 1))) { |
78 if(-1 == (ret = call_callback_function(L, 1))) { |
79 freeCallbackArgs(arg); |
79 freeCallbackArgs(arg); |
80 return; |
80 return; |
81 } |
81 } |
82 |
82 |
83 printf("RET VAL: %i\n", ret); |
|
84 if(event != ret) |
83 if(event != ret) |
85 setup_event(arg, fd, ret, 1); |
84 setup_event(arg, fd, ret, 1); |
86 } |
85 } |
87 |
86 |
88 static int luaevent_base_gc(lua_State* L) { |
87 static int luaevent_base_gc(lua_State* L) { |
124 luaL_getmetatable(L, EVENT_CALLBACK_ARG_MT); |
123 luaL_getmetatable(L, EVENT_CALLBACK_ARG_MT); |
125 lua_setmetatable(L, -2); |
124 lua_setmetatable(L, -2); |
126 |
125 |
127 arg->L = L; |
126 arg->L = L; |
128 arg->callbackRef = callbackRef; |
127 arg->callbackRef = callbackRef; |
129 |
128 lua_pushvalue(L, -1); |
|
129 arg->objectRef = luaL_ref(L, LUA_REGISTRYINDEX); |
130 setup_event(arg, fd, event, 0); |
130 setup_event(arg, fd, event, 0); |
131 } |
131 } |
132 /* Expected to be called at the beginning of the coro that uses it.. |
132 /* Expected to be called at the beginning of the coro that uses it.. |
133 Value must be kept until coro is complete.... |
133 Value must be kept until coro is complete.... |
134 */ |
134 */ |