src/event_callback.c

changeset 108
f123677dd748
parent 65
e65466cee871
child 109
df22d2e85fb0
equal deleted inserted replaced
107:f937d449075d 108:f123677dd748
22 le_callback* cb = p; 22 le_callback* cb = p;
23 lua_State* L; 23 lua_State* L;
24 int ret; 24 int ret;
25 double newTimeout = -1; 25 double newTimeout = -1;
26 assert(cb); 26 assert(cb);
27 if(!cb->base) { 27 if(!cb->base)
28 /* Callback has been collected... die */ 28 return; /* Event has already been collected + destroyed */
29 /* TODO: What should really be done here... */
30 return;
31 }
32 assert(cb->base->loop_L); 29 assert(cb->base->loop_L);
33 L = cb->base->loop_L; 30 L = cb->base->loop_L;
34 lua_rawgeti(L, LUA_REGISTRYINDEX, cb->callbackRef); 31 lua_rawgeti(L, LUA_REGISTRYINDEX, cb->callbackRef);
35 lua_pushinteger(L, event); 32 lua_pushinteger(L, event);
36 lua_call(L, 1, 2); 33 lua_call(L, 1, 2);
34 if(!cb->base)
35 return; /* event was destroyed during callback */
37 ret = lua_tointeger(L, -2); 36 ret = lua_tointeger(L, -2);
38 if(lua_isnumber(L, -1)) { 37 if(lua_isnumber(L, -1)) {
39 newTimeout = lua_tonumber(L, -1); 38 newTimeout = lua_tonumber(L, -1);
40 if(newTimeout <= 0) { 39 if(newTimeout <= 0) {
41 memset(&cb->timeout, 0, sizeof(cb->timeout)); 40 memset(&cb->timeout, 0, sizeof(cb->timeout));

mercurial