-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlib.rs
More file actions
36 lines (29 loc) · 745 Bytes
/
lib.rs
File metadata and controls
36 lines (29 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
extern crate libc;
use self::libc::c_int;
static mut HASKELL:Option<extern fn(c_int)> = None;
/* Register the callback */
#[no_mangle]
pub fn rs_register(cb: extern fn(c_int)) {
unsafe {
HASKELL = Some(cb);
println!("callback registered");
}
}
#[no_mangle]
pub fn rs_function(val:c_int) {
println!("triggered Rust function with: {}", val);
if val != 42 {
println!("life, the universe, and everything");
}
unsafe {
match HASKELL {
Some(ref callback) => {
println!("registered callback found");
(*callback)(100);
},
_ => {
println!("no callback has been registered");
}
}
}
}