2024-03-27 09:01:07 +00:00
|
|
|
# Host files
|
|
|
|
|
|
|
|
File path: `out/dir/api.rs`
|
|
|
|
|
|
|
|
```rust
|
|
|
|
// Host code
|
|
|
|
/* Rust API */
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Commands {
|
|
|
|
/// Call out an outstanding person
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
call_me_back_outstanding { callback: fn(String) -> String },
|
|
|
|
One(one::One),
|
|
|
|
}
|
|
|
|
pub mod one {
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum One {
|
|
|
|
/// Call out a person
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
call_me_back { callback: fn(u32) },
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* C API */
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn call_me_back_outstanding(
|
|
|
|
callback: fn(String) -> String,
|
|
|
|
) -> core::ffi::c_int {
|
|
|
|
callback_function(call_me_back_outstanding);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
pub mod one_c {}
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn one_call_me_back(callback: fn(u32)) -> core::ffi::c_int {
|
|
|
|
callback_function(one_call_me_back);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// vim: filetype=rust
|
|
|
|
```
|
|
|
|
|
|
|
|
# Auxiliary files
|
|
|
|
|
|
|
|
File path: `dist/interface.h`
|
|
|
|
|
|
|
|
```c
|
|
|
|
#if !defined TRIXY_MAIN_HEADER
|
|
|
|
#define TRIXY_MAIN_HEADER
|
|
|
|
|
|
|
|
#include "errno.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "vec.h"
|
|
|
|
|
|
|
|
/**
|
2024-03-27 09:51:39 +00:00
|
|
|
* Call out an outstanding person
|
|
|
|
*/
|
2024-03-27 10:08:37 +00:00
|
|
|
extern int call_me_back_outstanding (const char *(*callback) (const char *));
|
2024-03-27 09:01:07 +00:00
|
|
|
|
|
|
|
/**
|
2024-03-27 09:51:39 +00:00
|
|
|
* Call out a person
|
|
|
|
*/
|
2024-03-27 10:08:37 +00:00
|
|
|
extern int one_call_me_back (void (*callback) (uint32_t));
|
2024-03-27 09:01:07 +00:00
|
|
|
|
|
|
|
struct one
|
|
|
|
{
|
|
|
|
int (*call_me_back) ();
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct one one = {
|
|
|
|
.call_me_back = one_call_me_back,
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // if !defined TRIXY_MAIN_HEADER
|
|
|
|
// vim: filetype=c
|
|
|
|
```
|