56 lines
1.7 KiB
Plaintext
56 lines
1.7 KiB
Plaintext
|
// Lord have mercy on me
|
||
|
#[macro_export]
|
||
|
macro_rules! plugin_info {
|
||
|
($typ:ty, $name:literal, $version:literal, $license:literal) => {
|
||
|
|
||
|
lazy_static::lazy_static!(
|
||
|
static ref PLUGIN_INFO: $crate::PluginInfo = $crate::PluginInfo::new($name, $version, $license);
|
||
|
);
|
||
|
|
||
|
static mut PLUG: *mut $typ = std::ptr::null_mut() as *mut $typ;
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn plug_get_info() -> *const std::ffi::c_void {
|
||
|
PLUGIN_INFO.get_raw_ptr()
|
||
|
}
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn plug_init(ctx: *const $crate::ContextRaw) {
|
||
|
PLUG = std::alloc::alloc(std::alloc::Layout::new::<$typ>()) as *mut $typ;
|
||
|
*PLUG = <$typ>::new();
|
||
|
|
||
|
let ctx = $crate::Context::new(ctx);
|
||
|
(&mut *PLUG).init(ctx);
|
||
|
}
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn plug_pre_reload() -> *mut $typ {
|
||
|
//TODO: Untested
|
||
|
(&mut *PLUG).pre_reload();
|
||
|
return PLUG;
|
||
|
}
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn plug_post_reload(state: *mut $typ) {
|
||
|
//TODO: Untested
|
||
|
PLUG = state;
|
||
|
(&mut *PLUG).post_reload();
|
||
|
}
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn plug_poll(buf: *mut i8, len: std::ffi::c_uint) {
|
||
|
let mut buf = $crate::CBuffer::from_raw_parts_mut(buf, len as usize);
|
||
|
if let Err(_e) = (&mut *PLUG).poll(&mut buf) {
|
||
|
// TODO: Handle error maybe?
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[no_mangle]
|
||
|
unsafe extern "C" fn plug_free() {
|
||
|
std::alloc::dealloc(PLUG as *mut u8, std::alloc::Layout::new::<$typ>());
|
||
|
(&mut *PLUG).free();
|
||
|
}
|
||
|
|
||
|
};
|
||
|
}
|