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.
§Panics
Unless otherwise stated, all functions in this crate taking strings (be
that &str
, String
, etc) panic when the string contains embedded NUL
characters (\0
).
§Examples
#[macro_use]
extern crate hexchat_unsafe_plugin;
use std::pin::Pin;
use std::sync::Mutex;
use hexchat_unsafe_plugin::{Plugin, PluginHandle, HookHandle};
#[derive(Default)]
struct MyPlugin<'ph> {
cmd: Mutex<Option<HookHandle<'ph, 'ph>>>
}
unsafe impl<'ph> Plugin<'ph> for MyPlugin<'ph> {
fn init(self: Pin<&mut Self>, ph: &mut PluginHandle<'ph>, filename: &str, arg: Option<&str>) -> bool {
ph.register("myplugin", "0.1.0", "my simple plugin");
*self.cmd.lock().unwrap() = Some(ph.hook_command("hello-world", hexchat_unsafe_plugin::PRI_NORM, Some("prints 'Hello, World!'"), |ph, arg, arg_eol| {
ph.print("Hello, World!");
hexchat_unsafe_plugin::EAT_ALL
}));
true
}
}
hexchat_plugin!('ph, MyPlugin<'ph>);
Modules§
- list
- List support module.
Macros§
- hexchat_
plugin - Exports a hexchat plugin.
Structs§
- Context
- A context.
- Eat
- A status indicator for event callbacks. Indicates whether to continue processing, eat hexchat, eat plugin, or eat all.
- Event
Attrs - Event attributes.
- Hook
Handle - A hook handle.
- Invalid
Context Error - The error returned by
PluginHandle::with_context
when the context is not valid. - Plugin
Entry Handle - A virtual plugin.
- Plugin
Handle - A hexchat plugin handle, used to register hooks and interact with hexchat.
- Plugin
Pref List - An iterable list of plugin pref names.
- Plugin
Pref List Iter - An iterator over
PluginPrefList
. - Strip
- Stripping mode for
PluginHandle::strip
. - Valid
Context - A
PluginHandle
operating on a valid context. - Word
- Arguments passed to a hook, until the next argument.
- WordEol
- Arguments passed to a hook, until the end of the line.
Enums§
- InfoId
- A hexchat_get_info key.
- Plugin
Pref Error - Errors returned by
pluginpref_*
functions. - Pref
Value - A setting value, returned by
ValidContext::get_prefs
.
Constants§
- EAT_ALL
- Equivalent to HEXCHAT_EAT_ALL.
- EAT_
HEXCHAT - Equivalent to HEXCHAT_EAT_HEXCHAT.
- EAT_
NONE - Equivalent to HEXCHAT_EAT_NONE.
- EAT_
PLUGIN - Equivalent to HEXCHAT_EAT_PLUGIN.
- PRI_
HIGH - Equivalent to HEXCHAT_PRI_HIGH
- PRI_
HIGHEST - Equivalent to HEXCHAT_PRI_HIGHEST
- PRI_LOW
- Equivalent to HEXCHAT_PRI_LOW
- PRI_
LOWEST - Equivalent to HEXCHAT_PRI_LOWEST
- PRI_
NORM - Equivalent to HEXCHAT_PRI_NORM
Traits§
- Plugin
- A hexchat plugin.