Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static CALLBACKS: SyncLazy<Mutex<Vec<TestCallback>>> = SyncLazy::new(|| Mutex::new(vec![]));
- struct TestCallback {
- callback_fn: extern "C" fn(*const u8),
- }
- #[no_mangle]
- pub extern "C" fn create_callback(callback: extern "C" fn(*const u8)) {
- let mut lock = CALLBACKS.lock();
- lock.push(TestCallback{
- callback_fn: callback,
- })
- }
- #[no_mangle]
- pub extern "C" fn call_callback(idx: usize, structure: *const u8) {
- let lock = CALLBACKS.lock();
- (&lock[idx].callback_fn)(structure);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement