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:
/tclSyntax by languagePerl
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 APIregister
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_nameset_charsetplugin_get_namecharset_seticonv_to_internaliconv_from_internalgettextngettextstring_remove_colormkdir_homemkdirmkdir_parentslist_newlist_addlist_searchlist_casesearchlist_getlist_setlist_nextlist_prevlist_stringlist_sizelist_removelist_remove_alllist_freeconfig_newconfig_new_sectionconfig_search_sectionconfig_new_optionconfig_search_optionconfig_string_to_booleanconfig_option_resetconfig_option_setconfig_option_set_nullconfig_option_unsetconfig_option_renameconfig_option_is_nullconfig_option_default_is_nullconfig_booleanconfig_boolean_defaultconfig_integerconfig_integer_defaultconfig_stringconfig_string_defaultconfig_colorconfig_color_defaultconfig_write_optionconfig_write_lineconfig_writeconfig_readconfig_reloadconfig_option_freeconfig_section_free_optionsconfig_section_freeconfig_freeconfig_getconfig_get_pluginconfig_set_pluginconfig_unset_pluginprefixcolorprintprint_date_tagsprint_ylog_printhook_commandhook_command_runhook_timerhook_fdhook_processhook_connecthook_printhook_signalhook_signal_sendhook_confighook_completionhook_completion_list_addhook_modifierhook_modifier_exechook_infohook_infolistunhookunhook_allbuffer_newbuffer_searchcurrent_bufferbuffer_clearbuffer_closebuffer_get_integerbuffer_get_stringbuffer_get_pointerbuffer_setcurrent_windowwindow_get_integerwindow_get_stringwindow_get_pointernicklist_add_groupnicklist_search_groupnicklist_add_nicknicklist_search_nicknicklist_remove_groupnicklist_remove_nicknicklist_remove_allbar_item_searchbar_item_newbar_item_updatebar_item_removebar_searchbar_newbar_setbar_updatebar_removecommandinfo_getinfolist_newinfolist_new_var_integerinfolist_new_var_stringinfolist_new_var_pointerinfolist_new_var_timeinfolist_getinfolist_nextinfolist_previnfolist_fieldsinfolist_integerinfolist_stringinfolist_pointerinfolist_timeinfolist_freeupgrade_newupgrade_write_objectupgrade_readupgrade_close