Skip to content

Instantly share code, notes, and snippets.

@matematikaadit
Created September 9, 2019 07:52
Show Gist options
  • Save matematikaadit/a22fc2898391e1707ad684c01993b8d8 to your computer and use it in GitHub Desktop.
Save matematikaadit/a22fc2898391e1707ad684c01993b8d8 to your computer and use it in GitHub Desktop.
// plugin.rs
// This code should be compiled into a shared library
#![crate_type="dylib"]
#![allow(dead_code, unused_variables)]
use std::os::raw;
// function provided by the glue code
extern "C" {
fn hook_event(
external: *mut External,
event: u32,
callback: unsafe extern "C" fn(data: *mut raw::c_void),
callback_data: *mut raw::c_void,
);
}
// type provided by the glue code
#[repr(C)]
#[derive(Copy, Clone)]
pub struct External {
_unused: [u8; 24], // just for example
}
#[repr(i32)]
#[derive(Copy, Clone)]
pub enum Result {
Ok = 0,
OkEat = 1,
Error = -1,
}
#[no_mangle]
pub extern "C" fn plugin_init(external: *mut External) -> Result {
// plugin author (you) need to write this
Result::Ok
}
#[no_mangle]
pub extern "C" fn plugin_end(external: *mut External) -> Result {
// plugin author (you) need to write this
Result::Ok
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment