The place where you your code will be executed when it's loaded and unloaded, respectively
int weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]);
int weechat_plugin_end (struct t_weechat_plugin *plugin);
t_weechat_plugin
is the struct that provides the plugin api.argc
andargv
is the argument passed to the plugin when it's loaded, manually via/plugin load
command or when weechat started for autoloaded plugin. See the weechat_plugin_init for more explanation.
WEECHAT_RC_OK
if successful (plugin will be loaded)WEECHAT_RC_ERROR
if error (plugin will NOT be loaded)
The weechat_plugin_init
is basically the main
function of your plugin. That's where the real stuff happen. The weechat_plugin_end
is for when you need to free stuff that you allocated previously.
#[no_mangle]
pub extern "C" weechat_plugin_init(plugin: *mut t_weechat_plugin,
argc: libc::c_int,
argv: *mut *mut libc::c_char) -> libc::c_int {
// Your rust code here
// ...
}
#[no_mangle]
pub extern "C" weechat_plugin_end(plugin: *mut t_weechat_plugin) -> libc::c_int {
// Your rust code here
// ...
}
Note: When an API takes a callback
, it also takes an argument of callback_pointer
and callback_data
.
callback_pointer
: passed to the callback, won't be freed.callback_data
: passed to the callback, managed by weechat. will be freed when the hook is unhooked.
The name must be unique for the plugin.
struct t_gui_buffer *weechat_buffer_new (const char *name,
int (*input_callback)(const void *pointer,
void *data,
struct t_gui_buffer *buffer,
const char *input_data),
const void *input_callback_pointer,
void *input_callback_data,
int (*close_callback)(const void *pointer,
void *data,
struct t_gui_buffer *buffer),
const void *close_callback_pointer,
void *close_callback_data);
#define weechat_buffer_new(__name, __input_callback, \
__input_callback_pointer, \
__input_callback_data, \
__close_callback, \
__close_callback_pointer, \
__close_callback_data) \
(weechat_plugin->buffer_new)(weechat_plugin, __name, \
__input_callback, \
__input_callback_pointer, \
__input_callback_data, \
__close_callback, \
__close_callback_pointer, \
__close_callback_data)
NOTE: *_callback_data
is pointer given to the callback when it's called by WeeChat; If not NULL, it must have been allocated with malloc and it's automatically freed when the buffer is clsed.
Hook a message printed. It is called when a line has been added in a buffer with formatted content.
struct t_hook *weechat_hook_print (struct t_gui_buffer *buffer,
const char *tags,
const char *message,
int strip_colors,
int (*callback)(const void *pointer,
void *data,
struct t_gui_buffer *buffer,
time_t date,
int tags_count,
const char **tags,
int displayed,
int highlight,
const char *prefix,
const char *message),
const void *callback_pointer,
void *callback_data);
#define weechat_hook_print(__buffer, __tags, __msg, __strip__colors, \
__callback, __pointer, __data) \
(weechat_plugin->hook_print)(weechat_plugin, __buffer, __tags, \
__msg, __strip__colors, __callback, \
__pointer, __data)
- If the
buffer
is NULL, capture message from any buffer. Otherwise, capture message for thatbuffer
. tags
andmessage
for capturing the message containing them. See hook_print for more explanation.
Return string value of buffer property (there are other type too such as integer and pointer).
const char *weechat_buffer_get_string (struct t_gui_buffer *buffer,
const char *property);
#define weechat_buffer_get_string(__buffer, __property) \
(weechat_plugin->buffer_get_string)(__buffer, __property)
See also: String property "plugin" (for "irc" plugin) and "type" (for "channel" type). And also "localvar_channel" for localvar channel name. More on buffer_get_string.
void weechat_printf_date_tags (struct t_gui_buffer *buffer, time_t date,
const char *tags, const char *message, ...);
#define weechat_printf_date_tags(__buffer, __date, __tags, __message, \
__argz...) \
(weechat_plugin->printf_date_tags)(__buffer, __date, __tags, \
__message, ##__argz)
void weechat_log_printf (const char *message, ...);
#define weechat_log_printf(__message, __argz...) \
(weechat_plugin->log_printf)(__message, ##__argz)
void weechat_buffer_set (struct t_gui_buffer *buffer, const char *property,
const char *value);
#define weechat_buffer_set(__buffer, __property, __value) \
(weechat_plugin->buffer_set)(__buffer, __property, __value)
See also: "hotlist" property and WEECHAT_HOTLIST_HIGHLIGHT