void weechat_ruby_unload (struct t_plugin_script *script) { int *rc; void *interpreter; if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet) { weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), RUBY_PLUGIN_NAME, script->name); } if (script->shutdown_func && script->shutdown_func[0]) { rc = (int *)weechat_ruby_exec (script, WEECHAT_SCRIPT_EXEC_INT, script->shutdown_func, 0, NULL); if (rc) free (rc); } interpreter = script->interpreter; if (ruby_current_script == script) ruby_current_script = (ruby_current_script->prev_script) ? ruby_current_script->prev_script : ruby_current_script->next_script; script_remove (weechat_ruby_plugin, &ruby_scripts, &last_ruby_script, script); if (interpreter) rb_gc_unregister_address (interpreter); }
void weechat_guile_unload (struct t_plugin_script *script) { int *rc; if ((weechat_guile_plugin->debug >= 1) || !guile_quiet) { weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), GUILE_PLUGIN_NAME, script->name); } if (script->shutdown_func && script->shutdown_func[0]) { rc = (int *)weechat_guile_exec (script, WEECHAT_SCRIPT_EXEC_INT, script->shutdown_func, NULL, NULL); if (rc) free (rc); } weechat_guile_catch (scm_gc_unprotect_object, script->interpreter); if (guile_current_script == script) guile_current_script = (guile_current_script->prev_script) ? guile_current_script->prev_script : guile_current_script->next_script; script_remove (weechat_guile_plugin, &guile_scripts, &last_guile_script, script); }
void weechat_tcl_unload (struct t_plugin_script *script) { Tcl_Interp* interp; int *rc; if ((weechat_tcl_plugin->debug >= 1) || !tcl_quiet) { weechat_printf (NULL, weechat_gettext ("%s: unloading script \"%s\""), TCL_PLUGIN_NAME, script->name); } if (script->shutdown_func && script->shutdown_func[0]) { rc = (int *)weechat_tcl_exec (script, WEECHAT_SCRIPT_EXEC_INT, script->shutdown_func, NULL, NULL); if (rc) free (rc); } interp = (Tcl_Interp*)script->interpreter; if (tcl_current_script == script) tcl_current_script = (tcl_current_script->prev_script) ? tcl_current_script->prev_script : tcl_current_script->next_script; script_remove (weechat_tcl_plugin, &tcl_scripts, &last_tcl_script, script); Tcl_DeleteInterp(interp); }
void weechat_guile_module_init_script (void *data) { SCM rc; weechat_guile_catch (scm_c_eval_string, "(use-modules (weechat))"); rc = weechat_guile_catch (scm_c_primitive_load, data); /* error loading script? */ if (rc == SCM_BOOL_F) { /* if script was registered, remove it from list */ if (guile_current_script) { script_remove (weechat_guile_plugin, &guile_scripts, &last_guile_script, guile_current_script); } guile_current_script = NULL; guile_registered_script = NULL; } }
int weechat_ruby_load (const char *filename) { char modname[64]; VALUE curModule, ruby_retcode, err, argv[1]; int ruby_error; struct stat buf; if (stat (filename, &buf) != 0) { weechat_printf (NULL, weechat_gettext ("%s%s: script \"%s\" not found"), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); return 0; } if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet) { weechat_printf (NULL, weechat_gettext ("%s: loading script \"%s\""), RUBY_PLUGIN_NAME, filename); } ruby_current_script = NULL; ruby_registered_script = NULL; snprintf (modname, sizeof(modname), "%s%d", MOD_NAME_PREFIX, ruby_num); ruby_num++; curModule = rb_define_module(modname); ruby_current_script_filename = filename; argv[0] = rb_str_new2 (filename); ruby_retcode = rb_protect_funcall (curModule, rb_intern("load_eval_file"), &ruby_error, 1, argv); if (ruby_retcode == Qnil) { err = rb_gv_get("$!"); weechat_ruby_print_exception(err); return 0; } if (NUM2INT(ruby_retcode) != 0) { switch (NUM2INT(ruby_retcode)) { case 1: weechat_printf (NULL, weechat_gettext ("%s%s: unable to read file " "\"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); break; case 2: weechat_printf (NULL, weechat_gettext ("%s%s: error while loading " "file \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); break; case 3: weechat_printf (NULL, weechat_gettext ("%s%s: function " "\"weechat_init\" is missing " "in file \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); break; } if (NUM2INT(ruby_retcode) == 1 || NUM2INT(ruby_retcode) == 2) { weechat_ruby_print_exception(rb_iv_get(curModule, "@load_eval_file_error")); } return 0; } (void) rb_protect_funcall (curModule, rb_intern("weechat_init"), &ruby_error, 0, NULL); if (ruby_error) { weechat_printf (NULL, weechat_gettext ("%s%s: unable to eval function " "\"weechat_init\" in file \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); err = rb_gv_get("$!"); weechat_ruby_print_exception(err); if (ruby_current_script != NULL) { script_remove (weechat_ruby_plugin, &ruby_scripts, &last_ruby_script, ruby_current_script); } return 0; } if (!ruby_registered_script) { weechat_printf (NULL, weechat_gettext ("%s%s: function \"register\" not " "found (or failed) in file \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); return 0; } ruby_current_script = ruby_registered_script; ruby_current_script->interpreter = (VALUE *) curModule; rb_gc_register_address (ruby_current_script->interpreter); /* * set input/close callbacks for buffers created by this script * (to restore callbacks after upgrade) */ script_set_buffer_callbacks (weechat_ruby_plugin, ruby_scripts, ruby_current_script, &weechat_ruby_api_buffer_input_data_cb, &weechat_ruby_api_buffer_close_cb); return 1; }
int weechat_ruby_load (const char *filename) { char modname[64]; VALUE curModule, ruby_retcode, err; int ruby_error; struct stat buf; if (stat (filename, &buf) != 0) { weechat_printf (NULL, weechat_gettext ("%s%s: script \"%s\" not found"), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); return 0; } if ((weechat_ruby_plugin->debug >= 1) || !ruby_quiet) { weechat_printf (NULL, weechat_gettext ("%s: loading script \"%s\""), RUBY_PLUGIN_NAME, filename); } ruby_current_script = NULL; snprintf (modname, sizeof(modname), "%s%d", MOD_NAME_PREFIX, ruby_num); ruby_num++; curModule = rb_define_module(modname); ruby_current_script_filename = filename; ruby_retcode = rb_protect_funcall (curModule, rb_intern("load_eval_file"), &ruby_error, 1, rb_str_new2(filename)); if (ruby_retcode == Qnil) { err = rb_inspect(rb_gv_get("$!")); weechat_printf (NULL, weechat_gettext ("%s%s: error: \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, STR2CSTR(err)); return 0; } if (NUM2INT(ruby_retcode) != 0) { VALUE ruby_eval_error; switch (NUM2INT(ruby_retcode)) { case 1: weechat_printf (NULL, weechat_gettext ("%s%s: unable to read file " "\"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); break; case 2: weechat_printf (NULL, weechat_gettext ("%s%s: error while loading " "file \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); break; case 3: weechat_printf (NULL, weechat_gettext ("%s%s: function " "\"weechat_init\" is missing " "in file \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); break; } if (NUM2INT(ruby_retcode) == 1 || NUM2INT(ruby_retcode) == 2) { ruby_eval_error = rb_iv_get(curModule, "@load_eval_file_error"); if (ruby_eval_error) { weechat_printf (NULL, weechat_gettext ("%s%s: error: %s"), weechat_prefix ("error"), RUBY_PLUGIN_NAME, STR2CSTR(ruby_eval_error)); } } return 0; } ruby_retcode = rb_protect_funcall (curModule, rb_intern("weechat_init"), &ruby_error, 0); if (ruby_error) { weechat_printf (NULL, weechat_gettext ("%s%s: unable to eval function " "\"weechat_init\" in file \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); err = rb_inspect(rb_gv_get("$!")); weechat_printf (NULL, weechat_gettext ("%s%s: error: \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, STR2CSTR(err)); if (ruby_current_script != NULL) { script_remove (weechat_ruby_plugin, &ruby_scripts, &last_ruby_script, ruby_current_script); } return 0; } if (ruby_current_script == NULL) { weechat_printf (NULL, weechat_gettext ("%s%s: function \"register\" not " "found (or failed) in file \"%s\""), weechat_prefix ("error"), RUBY_PLUGIN_NAME, filename); return 0; } ruby_current_script->interpreter = (VALUE *) curModule; rb_gc_register_address (ruby_current_script->interpreter); return 1; }