Script plugin API Five plugins are provided with WeeChat to use script languages: Perl, Python, Ruby, Lua and Tcl.
Load / unload scripts Scripts are loaded and unloaded with /perl, /python, /ruby, /lua and /tcl commands (type /help in WeeChat for help about commands). Examples: Load a Perl script: /perl load /tmp/test.pl List all loaded Perl scripts: /perl Load a Python script: /python load /tmp/test.py List all loaded Python scripts: /python Load a Ruby script: /ruby load /tmp/test.rb List all loaded Ruby scripts: /ruby Load a Lua script: /lua load /tmp/test.lua List all loaded Lua scripts: /lua Load a Tcl script: /tcl load /tmp/test.tcl List all loaded Tcl scripts: /tcl
Syntax by language
Perl In a WeeChat Perl script, all API functions and variables are prefixed by "weechat::". Example: weechat::register("test", "Author <author\@domain.com>", "1.0", "GPL3", "Script description", "bye_bye", "");
Python A WeeChat Python script has to start by importing weechat: import weechat All API functions and variables are prefixed by "weechat.". Example: weechat.register("test", "Author <author@domain.com>", "1.0", "GPL3", "Script description", "bye_bye", "")
Ruby In a WeeChat Ruby script, all code has to be in functions. So for main code, you have to define a "weechat_init" function, which is automatically called when script is loaded by WeeChat. Example: def weechat_init Weechat.register("test", "Author <author@domain.com>", "1.0", "GPL3", "Script description", "bye_bye", "") return Weechat::WEECHAT_RC_OK end All API functions are prefixed by "Weechat." and variables by "Weechat::".
Lua In a WeeChat Lua script, all API functions are prefixed by "weechat.". Variables are prefixed by "weechat." and suffixed by "()". Example: weechat.register("test", "Author <author@domain.com>", "1.0", "GPL3", "Script description", "bye_bye", "")
Tcl In a WeeChat Tcl script, all API functions are prefixed by "weechat::". Variables are prefixed by "$weechat::". Example: weechat::register "test" "Author <author@domain.com>" "1.0" "GPL3" "Script description" "bye_bye" ""
WeeChat / scripts API
register Perl prototype: weechat::register(name, author, version, license, description, end_function, charset); Python prototype: weechat.register(name, author, version, license, description, end_function, charset) Ruby prototype: Weechat.register(name, author, version, license, description, end_function, charset) Lua prototype: weechat.register(name, author, version, license, description, end_function, charset) Tcl prototype: weechat::register name author version license description end_function charset This is first function to call in script. All WeeChat scripts have to call this function. Arguments: : unique name to identify script (each script must have unique name) : string with author (may include name, nick, e-mail, ..) : script version : short description of script : function called when script is unloaded (optional parameter, empty string means nothing is called at the end) : charset used by script, you should set this if script is NOT written with UTF-8 (you can use blank value for UTF-8 script, which is default charset) Return value: 1 if script was registered, 0 if an error occured. Examples: # perl weechat::register("test", "Author <author\@domain.com>", "1.0", "GPL3", "Script description", "bye_bye", ""); # python weechat.register("test", "Author <author@domain.com>", "1.0", "GPL3", "Script description", "bye_bye", "") # ruby Weechat.register("test", "Author <author@domain.com>", "1.0", "GPL3", "Script description", "bye_bye", "") -- lua weechat.register("test", "Author <author@domain.com>", "1.0", "GPL3", "Script description", "bye_bye", "") # tcl weechat::register "test" "Author <author@domain.com>" "1.0" "GPL3" "Script description" "bye_bye" ""
Other functions Following functions are in script API (for description, see ). plugin_get_name set_charset plugin_get_name charset_set iconv_to_internal iconv_from_internal gettext ngettext string_remove_color mkdir_home mkdir mkdir_parents list_new list_add list_search list_casesearch list_get list_set list_next list_prev list_string list_size list_remove list_remove_all list_free config_new config_new_section config_search_section config_new_option config_search_option config_string_to_boolean config_option_reset config_option_set config_option_set_null config_option_unset config_option_rename config_option_is_null config_option_default_is_null config_boolean config_boolean_default config_integer config_integer_default config_string config_string_default config_color config_color_default config_write_option config_write_line config_write config_read config_reload config_option_free config_section_free_options config_section_free config_free config_get config_get_plugin config_set_plugin config_unset_plugin prefix color print print_date_tags print_y log_print hook_command hook_command_run hook_timer hook_fd hook_process hook_connect hook_print hook_signal hook_signal_send hook_config hook_completion hook_completion_list_add hook_modifier hook_modifier_exec hook_info hook_infolist unhook unhook_all buffer_new buffer_search current_buffer buffer_clear buffer_close buffer_get_integer buffer_get_string buffer_get_pointer buffer_set current_window window_get_integer window_get_string window_get_pointer nicklist_add_group nicklist_search_group nicklist_add_nick nicklist_search_nick nicklist_remove_group nicklist_remove_nick nicklist_remove_all bar_item_search bar_item_new bar_item_update bar_item_remove bar_search bar_new bar_set bar_update bar_remove command info_get infolist_new infolist_new_var_integer infolist_new_var_string infolist_new_var_pointer infolist_new_var_time infolist_get infolist_next infolist_prev infolist_fields infolist_integer infolist_string infolist_pointer infolist_time infolist_free upgrade_new upgrade_write_object upgrade_read upgrade_close