Created
September 9, 2019 07:52
-
-
Save matematikaadit/a22fc2898391e1707ad684c01993b8d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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