Crate hexchat_plugin

source ·
Expand description

Write hexchat plugins in Rust!

This library provides safe API bindings for hexchat, but doesn’t attempt to fix hexchat’s own bugs. It makes no effort to stop you from unloading your own code while it’s still running, for example.

When using this library, it’s strongly recommended to avoid heap-allocated statics (static mutexes, lazy_static, etc). This is because it’s currently impossible to deallocate those on plugin unload. This can be worked around by placing those statics as fields in your plugin struct.

This caveat does not apply to static assets (static FOO: &'static str, for example), but it does apply to thread-local storage.

Examples

#[macro_use]
extern crate hexchat_plugin;

use std::sync::Mutex;
use hexchat_plugin::{Plugin, PluginHandle, CommandHookHandle};

#[derive(Default)]
struct MyPlugin {
    cmd: Mutex<Option<CommandHookHandle>>
}

impl Plugin for MyPlugin {
    fn init(&self, ph: &mut PluginHandle, arg: Option<&str>) -> bool {
        ph.register("myplugin", "0.1.0", "my simple plugin");
        *self.cmd.lock().unwrap() = Some(ph.hook_command("hello-world", |ph, arg, arg_eol| {
            ph.print("Hello, World!");
            hexchat_plugin::EAT_ALL
        }, hexchat_plugin::PRI_NORM, Some("prints 'Hello, World!'")));
        true
    }
}

hexchat_plugin!(MyPlugin);

Macros

Exports a hexchat plugin.

Structs

A command hook handle.
A context.
A status indicator for event callbacks. Indicates whether to continue processing, eat hexchat, eat plugin, or eat all.
A safety wrapper to ensure you’re working with a valid context.
Event attributes.
A hexchat plugin handle, used to register hooks and interact with hexchat.
A print hook handle.
A server hook handle.
A timer hook handle.
Arguments passed to a hook, until the next argument.
Arguments passed to a hook, until the end of the line.

Enums

A hexchat_get_info key.

Constants

Equivalent to HEXCHAT_EAT_ALL.
Equivalent to HEXCHAT_EAT_HEXCHAT.
Equivalent to HEXCHAT_EAT_NONE.
Equivalent to HEXCHAT_EAT_PLUGIN.
Equivalent to HEXCHAT_PRI_HIGH
Equivalent to HEXCHAT_PRI_HIGHEST
Equivalent to HEXCHAT_PRI_LOW
Equivalent to HEXCHAT_PRI_LOWEST
Equivalent to HEXCHAT_PRI_NORM

Traits

A hexchat plugin.