Plugins
This chapter describes WeeChat plugins interface (API) and
the default scripts plugins (Perl, Python, Ruby, Lua), provided with
WeeChat.
Plugins in WeeChat
A plugin is a C program which can call WeeChat functions defined in
an interface.
This C program does not need WeeChat sources to compile and can be
dynamically loaded into WeeChat with command
/plugin.
The plugin has to be a dynamic library, for dynamic loading by
operating system.
Under GNU/Linux, the file has ".so" extension, ".dll" under
Windows.
Write a plugin
The plugin has to include "weechat-plugin.h" file (available in
WeeChat source code).
This file defines structures and types used to communicate with
WeeChat.
The plugin must have some variables and functions (mandatory,
without them the plugin can't load):
Variable
Description
char plugin_name[]
plugin name
char plugin_version[]
plugin version
char plugin_description[]
short description of plugin
Function
Description
int weechat_plugin_init (t_weechat_plugin *plugin)
function called when plugin is loaded, must return
PLUGIN_RC_OK if successful, PLUGIN_RC_KO if error
(if error, plugin will NOT be loaded)
void weechat_plugin_end (t_weechat_plugin *plugin)
function called when plugin is unloaded
&plugin_api.en.xml;
Compile plugin
Compile does not need WeeChat sources, only file
"weechat-plugin.h".
To compile a plugin which has one file "toto.c" (under GNU/Linux):
$ gcc -fPIC -Wall -c toto.c
$ gcc -shared -fPIC -o libtoto.so toto.o
Load plugin into WeeChat
Copy "libtoto.so" file into system plugins directory (for example
"/usr/local/lib/weechat/plugins") or into
user's plugins directory (for example
"/home/xxxxx/.weechat/plugins").
Under WeeChat:
/plugin load toto
Plugin example
Full example of plugin, which adds a /double command, which displays
two times arguments on current channel (ok that's not very useful,
but that's just an example!):
#include <stdlib.h>
#include "weechat-plugin.h"
char plugin_name[] = "Double";
char plugin_version[] = "0.1";
char plugin_description[] = "Test plugin for WeeChat";
/* "/double" command manager */
int double_cmd (t_weechat_plugin *plugin, int argc, char **argv,
char *handler_args, void *handler_pointer)
{
if (argv[2] && (argv[2][0] != '/'))
{
plugin->exec_command (plugin, NULL, NULL, argv[2]);
plugin->exec_command (plugin, NULL, NULL, argv[2]);
}
return PLUGIN_RC_OK;
}
int weechat_plugin_init (t_weechat_plugin *plugin)
{
plugin->cmd_handler_add (plugin, "double",
"Display two times a message",
"msg",
"msg: message to display two times",
NULL,
&double_cmd,
NULL, NULL);
return PLUGIN_RC_OK;
}
void weechat_plugin_end (t_weechat_plugin *plugin)
{
/* nothing done here */
}
&plugin_charset.en.xml;
&plugin_scripts.en.xml;