int xchat_plugin_init (xchat_plugin * plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg) { if (initialized != 0) { xchat_print (plugin_handle, "Perl interface already loaded\n"); return 0; } ph = plugin_handle; initialized = 1; *plugin_name = "Perl"; *plugin_desc = "Perl scripting interface"; *plugin_version = PACKAGE_VERSION; xchat_hook_command (ph, "load", XCHAT_PRI_NORM, perl_command_load, 0, 0); xchat_hook_command (ph, "unload", XCHAT_PRI_NORM, perl_command_unload, 0, 0); xchat_hook_command (ph, "reload", XCHAT_PRI_NORM, perl_command_reload, 0, 0); xchat_hook_command (ph, "pl_reload", XCHAT_PRI_NORM, perl_command_reload, 0, 0); xchat_hook_command (ph, "unloadall", XCHAT_PRI_NORM, perl_command_unloadall, 0, 0); xchat_hook_command (ph, "reloadall", XCHAT_PRI_NORM, perl_command_reloadall, 0, 0); /*perl_init (); */ xchat_hook_timer (ph, 0, perl_auto_load, NULL ); xchat_print (ph, "Perl interface loaded\n"); return 1; }
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 VALUE static_ruby_xchat_hook_timer( VALUE klass, VALUE name, VALUE timeout ) { char *s_name; int i_timeout; xchat_hook *hook; VALUE v_hook; Check_Type( name, T_STRING ); Check_Type( timeout, T_FIXNUM ); s_name = StringValueCStr( name ); i_timeout = FIX2INT( timeout ); hook = xchat_hook_timer( static_plugin_handle, i_timeout, static_ruby_custom_timer_hook, (void*)name ); v_hook = Data_Wrap_Struct( static_xchat_hook_klass, NULL, NULL, hook ); return v_hook; }
void ScriptData::putAtSleep( Falcon::numeric seconds ) { if( m_pSleepHook != 0 ) { xchat_unhook( the_plugin, m_pSleepHook ); } int slt = (int)(seconds*1000); m_pSleepHook = xchat_hook_timer( the_plugin, slt, mod_sleep_timer_cb, this ); }
/* 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)); } }
static int lxc_hook_timer(lua_State *L) { xchat_hook *hook; struct lxc_hooks *hooks, *h; struct lxc_States *st; double timeout; const char *func; char name[32]; struct lxc_cbdata *cb = malloc(sizeof(struct lxc_cbdata)); if (!cb) { luaL_error(L, "lxc_hook_timer(): failed to malloc: %s", strerror(errno)); lua_pushnil(L); return 1; } if (lua_gettop(L) < 3) /* expand to 3 args if necessary */ lua_settop(L, 3); timeout = luaL_checknumber(L, 1); func = luaL_checkstring(L, 2); cb->state = L; cb->func = func; cb->data = NULL; if (lxc_get_userdata(3, cb) == 0) lua_pushnil(L); else { h = malloc(sizeof(struct lxc_hooks)); if (!h) { luaL_error(L, "lxc_hook_timer(): failed to malloc: %s", strerror(errno)); return 0; } hook = xchat_hook_timer(ph, timeout, lxc_run_timer, cb); cb->hook = hook; h->hook = hook; h->next = NULL; snprintf(name, 31, "timer%llu", lxc_timer_count++); h->name = name; lua_pushstring(L, name); st = lxc_states; while (st) { if (st->state == L) { if (!st->hooks) st->hooks = h; else { hooks = st->hooks; while (hooks->next) hooks = hooks->next; hooks->next = h; } break; } st = st->next; } } return 1; }