1208 return ret; |
1208 return ret; |
1209 } |
1209 } |
1210 |
1210 |
1211 /// mcabber.timer |
1211 /// mcabber.timer |
1212 /// Creates new timer function, that will be called periodically. |
1212 /// Creates new timer function, that will be called periodically. |
1213 /// A: integer (interval, seconds), timer function |
1213 /// A: float (interval, seconds), timer function |
1214 static int lua_main_timer (lua_State *L) |
1214 static int lua_main_timer (lua_State *L) |
1215 { |
1215 { |
1216 int interval = luaL_checkinteger (L, 1); |
1216 lua_Number interval = luaL_checknumber (L, 1); |
1217 guint source; |
1217 guint source; |
1218 lua_timer_callback_t *cb; |
1218 lua_timer_callback_t *cb; |
1219 luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
1219 luaL_argcheck (L, lua_isfunction (L, 2), 2, "function expected"); |
1220 |
1220 |
1221 cb = luaL_malloc (L, sizeof (lua_timer_callback_t)); |
1221 cb = luaL_malloc (L, sizeof (lua_timer_callback_t)); |
1222 cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
1222 cb->reference = luaL_ref (L, LUA_REGISTRYINDEX); |
1223 cb->L = L; |
1223 cb->L = L; |
1224 |
1224 |
1225 source = g_timeout_add_seconds_full (MLUA_SOURCE_PRIORITY, interval, (GSourceFunc) lua_timer_callback, cb, (GDestroyNotify) lua_timer_callback_destroy); |
1225 source = g_timeout_add_full (MLUA_SOURCE_PRIORITY, |
|
1226 (guint) ( interval*1000 ), |
|
1227 (GSourceFunc) lua_timer_callback, |
|
1228 cb, |
|
1229 (GDestroyNotify) lua_timer_callback_destroy); |
1226 cb->source = source; |
1230 cb->source = source; |
1227 lua_timers = g_slist_prepend (lua_timers, (gpointer) ((gsize) source)); |
1231 lua_timers = g_slist_prepend (lua_timers, (gpointer) ((gsize) source)); |
1228 |
1232 |
1229 return 0; |
1233 return 0; |
1230 } |
1234 } |