Beispiel #1
0
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
    weechat_guile_plugin = plugin;

    guile_stdout = NULL;

    scm_init_guile ();

    guile_module_weechat = scm_c_define_module ("weechat",
                                                &weechat_guile_api_module_init,
                                                NULL);
    scm_c_use_module ("weechat");
    weechat_guile_catch (scm_gc_protect_object, (void *)guile_module_weechat);

    guile_quiet = 1;
    script_init (weechat_guile_plugin,
                 argc,
                 argv,
                 &weechat_guile_command_cb,
                 &weechat_guile_completion_cb,
                 &weechat_guile_infolist_cb,
                 &weechat_guile_signal_debug_dump_cb,
                 &weechat_guile_signal_buffer_closed_cb,
                 &weechat_guile_signal_script_action_cb,
                 &weechat_guile_load_cb);
    guile_quiet = 0;

    script_display_short_list (weechat_guile_plugin,
                               guile_scripts);

    /* init ok */
    return WEECHAT_RC_OK;
}
Beispiel #2
0
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
    weechat_tcl_plugin = plugin;

    tcl_quiet = 1;
    script_init (weechat_tcl_plugin,
                 argc,
                 argv,
                 &weechat_tcl_command_cb,
                 &weechat_tcl_completion_cb,
                 &weechat_tcl_infolist_cb,
                 &weechat_tcl_signal_debug_dump_cb,
                 &weechat_tcl_signal_buffer_closed_cb,
                 &weechat_tcl_signal_script_action_cb,
                 &weechat_tcl_load_cb);
    tcl_quiet = 0;

    script_display_short_list (weechat_tcl_plugin,
                               tcl_scripts);

    /* init ok */
    return WEECHAT_RC_OK;
}
Beispiel #3
0
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
    int ruby_error;
    char *weechat_ruby_code =
        {
            "$stdout = WeechatOutputs\n"
            "$stderr = WeechatOutputs\n"
            "begin"
            "  if RUBY_VERSION.split('.')[1] == '9'\n"
            "    require 'enc/encdb.so'\n"
            "    require 'enc/trans/transdb.so'\n"
            "\n"
            "    require 'thread'\n"
            "    class ::Mutex\n"
            "      def synchronize(*args)\n"
            "        yield\n"
            "      end\n"
            "    end\n"
            "    require 'rubygems'\n"
            "  else\n"
            "    require 'rubygems'\n"
            "  end\n"
            "rescue LoadError\n"
            "end\n"
            "\n"
            "class Module\n"
            "\n"
            "  def load_eval_file (file)\n"
            "    lines = ''\n"
            "    begin\n"
            "      lines = File.read(file)\n"
            "    rescue => e\n"
            "      return 1\n"
            "    end\n"
            "\n"
            "    begin\n"
            "      module_eval(lines)\n"
            "    rescue Exception => e\n"
            "      @load_eval_file_error = e\n"
            "      return 2\n"
            "    end\n"
            "\n"
            "    has_init = false\n"
            "\n"
            "    instance_methods.each do |meth|\n"
            "      if meth.to_s == 'weechat_init'\n"
            "        has_init = true\n"
            "      end\n"
            "      module_eval('module_function :' + meth.to_s)\n"
            "    end\n"
            "\n"
            "    unless has_init\n"
            "      return 3\n"
            "    end\n"
            "\n"
            "    return 0\n"
            "  end\n"
            "end\n"
        };

    weechat_ruby_plugin = plugin;

    ruby_error = 0;

    /* init stdout/stderr buffer */
    ruby_buffer_output[0] = '\0';

#if defined(RUBY_VERSION) && RUBY_VERSION >= 19
    RUBY_INIT_STACK;
#endif

    ruby_hide_errors = 1;
    ruby_init ();
    ruby_init_loadpath ();
    ruby_script ("__weechat_plugin__");

    ruby_mWeechat = rb_define_module("Weechat");
    weechat_ruby_api_init (ruby_mWeechat);

    /* redirect stdin and stdout */
    ruby_mWeechatOutputs = rb_define_module("WeechatOutputs");
    rb_define_singleton_method(ruby_mWeechatOutputs, "write",
                               weechat_ruby_output, 1);
    rb_define_singleton_method(ruby_mWeechatOutputs, "puts",
                               weechat_ruby_output, 1);
    rb_define_singleton_method(ruby_mWeechatOutputs, "p",
                               weechat_ruby_output, 1);
    rb_define_singleton_method(ruby_mWeechatOutputs, "flush",
                               weechat_ruby_output_flush, 0);
    ruby_hide_errors = 0;

    rb_eval_string_protect(weechat_ruby_code, &ruby_error);
    if (ruby_error)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s%s: unable to eval WeeChat ruby "
                                         "internal code"),
                        weechat_prefix ("error"), RUBY_PLUGIN_NAME);
        VALUE err = rb_gv_get("$!");
        weechat_ruby_print_exception(err);
        return WEECHAT_RC_ERROR;
    }

    ruby_quiet = 1;
    script_init (weechat_ruby_plugin,
                 argc,
                 argv,
                 &weechat_ruby_command_cb,
                 &weechat_ruby_completion_cb,
                 &weechat_ruby_infolist_cb,
                 &weechat_ruby_signal_debug_dump_cb,
                 &weechat_ruby_signal_buffer_closed_cb,
                 &weechat_ruby_signal_script_action_cb,
                 &weechat_ruby_load_cb);
    ruby_quiet = 0;

    script_display_short_list (weechat_ruby_plugin,
                               ruby_scripts);

    /* init ok */
    return WEECHAT_RC_OK;
}
Beispiel #4
0
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
    int ruby_error;
    char *weechat_ruby_code =
        {
            "$stdout = WeechatOutputs\n"
            "$stderr = WeechatOutputs\n"
            "\n"
            "class Module\n"
            "  @load_eval_file_error = ''\n"
            "\n"
            "  def load_eval_file (file)\n"
            "    lines = ''\n"
	    "    begin\n"
	    "      f = File.open(file, 'r')\n"
	    "      lines = f.readlines.join\n"
	    "    rescue => e\n"
	    "      @load_eval_file_error = e\n"
	    "      return 1\n"
	    "    end\n"
	    "\n"	   
	    "    begin\n"
	    "      module_eval(lines)\n"
	    "    rescue => e\n"
	    "      @load_eval_file_error = e\n"
	    "      return 2\n"
	    "    end\n"
	    "\n"
	    "    has_init = false\n"
	    "\n"
	    "    instance_methods.each do |meth|\n"
	    "      if meth == 'weechat_init'\n"
	    "        has_init = true\n"
	    "      end\n"
	    "      module_eval('module_function :' + meth)\n"
	    "    end\n"
	    "\n"
	    "    unless has_init\n"
	    "      return 3\n"
	    "    end\n"
	    "\n"
	    "    return 0\n"
	    "  end\n"
	    "end\n"
	};
    
    weechat_ruby_plugin = plugin;
    
    ruby_error = 0;
    
    /* init stdout/stderr buffer */
    ruby_buffer_output[0] = '\0';
    
    ruby_init ();
    ruby_init_loadpath ();
    ruby_script ("__weechat_plugin__");
    
    ruby_mWeechat = rb_define_module("Weechat");
    weechat_ruby_api_init (ruby_mWeechat);
    
    /* redirect stdin and stdout */
    ruby_mWeechatOutputs = rb_define_module("WeechatOutputs");
    rb_define_singleton_method(ruby_mWeechatOutputs, "write",
                               weechat_ruby_output, 1);
    rb_define_singleton_method(ruby_mWeechatOutputs, "puts",
                               weechat_ruby_output, 1);
    rb_define_singleton_method(ruby_mWeechatOutputs, "p",
                               weechat_ruby_output, 1);
    rb_define_singleton_method(ruby_mWeechatOutputs, "flush",
                               weechat_ruby_output_flush, 0);

    rb_eval_string_protect(weechat_ruby_code, &ruby_error);
    if (ruby_error)
    {
	VALUE ruby_error_info = rb_inspect(ruby_errinfo);
	weechat_printf (NULL,
                        weechat_gettext ("%s%s: unable to eval WeeChat ruby "
                                         "internal code"),
                        weechat_prefix ("error"), RUBY_PLUGIN_NAME);
	weechat_printf (NULL,
                        weechat_gettext ("%s%s: error: %s"),
                        weechat_prefix ("error"), RUBY_PLUGIN_NAME,
                        STR2CSTR(ruby_error_info));
	return WEECHAT_RC_ERROR;
    }
    
    ruby_quiet = 1;
    script_init (weechat_ruby_plugin,
                 argc,
                 argv,
                 &ruby_scripts,
                 &weechat_ruby_command_cb,
                 &weechat_ruby_completion_cb,
                 &weechat_ruby_infolist_cb,
                 &weechat_ruby_signal_debug_dump_cb,
                 &weechat_ruby_signal_buffer_closed_cb,
                 &weechat_ruby_signal_script_action_cb,
                 &weechat_ruby_load_cb,
                 &weechat_ruby_api_buffer_input_data_cb,
                 &weechat_ruby_api_buffer_close_cb);
    ruby_quiet = 0;
    
    script_display_short_list (weechat_ruby_plugin,
                               ruby_scripts);
    
    /* init ok */
    return WEECHAT_RC_OK;
}