static void timer_add(int ref, float timeout, int repeat, char *command) { timer *tim; GSList *list; if (ref == 0) { ref = 1; list = timer_list; while (list) { tim = list->data; if (tim->ref >= ref) ref = tim->ref + 1; list = list->next; } } tim = malloc(sizeof(timer)); tim->ref = ref; tim->repeat = repeat; tim->timeout = timeout; tim->command = strdup(command); tim->context = xchat_get_context(ph); tim->forever = FALSE; if (repeat == 0) tim->forever = TRUE; tim->hook = xchat_hook_timer(ph, timeout * 1000.0, (void *)timeout_cb, tim); timer_list = g_slist_append(timer_list, tim); }
static XS (XS_Xchat_get_context) { dXSARGS; if (items != 0) { xchat_print (ph, "Usage: Xchat::get_context()"); } else { XSRETURN_IV (PTR2IV (xchat_get_context (ph))); } }
/* * lua: xchat.get_context() * desc: Returns the current context for your plugin. You can use this later * with xchat_set_context. * ret: context number ... DON'T modifiy * args: none */ static int lxc_get_context(lua_State *L) { long ptr; xchat_context *ctx = xchat_get_context(ph); ptr = (long)ctx; #ifdef DEBUG fprintf(stderr, "get_context(): %#lx\n", ptr); #endif lua_pushnumber(L, (double)ptr); return 1; }
static VALUE static_ruby_xchat_get_context( VALUE klass ) { xchat_context *ctx; VALUE v_ctx; ctx = xchat_get_context( static_plugin_handle ); v_ctx = Data_Wrap_Struct( static_xchat_context_klass, NULL, NULL, ctx ); return v_ctx; }
/* Xchat::Internal::hook_timer(timeout, callback, userdata) */ static XS (XS_Xchat_hook_timer) { int timeout; SV *callback; SV *userdata; xchat_hook *hook; SV *package; HookData *data; dXSARGS; if (items != 4) { xchat_print (ph, "Usage: Xchat::Internal::hook_timer(timeout, callback, userdata, package)"); } else { timeout = (int) SvIV (ST (0)); callback = ST (1); data = NULL; userdata = ST (2); package = ST (3); data = malloc (sizeof (HookData)); if (data == NULL) { XSRETURN_UNDEF; } data->callback = sv_mortalcopy (callback); SvREFCNT_inc (data->callback); data->userdata = sv_mortalcopy (userdata); SvREFCNT_inc (data->userdata); data->ctx = xchat_get_context (ph); data->package = sv_mortalcopy (package); SvREFCNT_inc (data->package); hook = xchat_hook_timer (ph, timeout, timer_cb, data); data->hook = hook; XSRETURN_IV (PTR2IV (hook)); } }