Advertisement
Ardente

Untitled

May 17th, 2022
1,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.52 KB | None | 0 0
  1. static CALLBACKS: SyncLazy<Mutex<Vec<TestCallback>>> = SyncLazy::new(|| Mutex::new(vec![]));
  2.  
  3. struct TestCallback {
  4.     callback_fn: extern "C" fn(*const u8),
  5. }
  6.  
  7. #[no_mangle]
  8. pub extern "C" fn create_callback(callback: extern "C" fn(*const u8)) {
  9.     let mut lock = CALLBACKS.lock();
  10.  
  11.     lock.push(TestCallback{
  12.         callback_fn: callback,
  13.     })
  14. }
  15.  
  16. #[no_mangle]
  17. pub extern "C" fn call_callback(idx: usize, structure: *const u8) {
  18.     let lock = CALLBACKS.lock();
  19.  
  20.     (&lock[idx].callback_fn)(structure);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement