2024-03-26 16:08:49 +00:00
|
|
|
# Host files
|
2024-03-26 16:28:21 +00:00
|
|
|
|
2024-03-26 16:08:49 +00:00
|
|
|
File path: `out/dir/api.rs`
|
2024-03-26 16:28:21 +00:00
|
|
|
|
2024-03-26 16:08:49 +00:00
|
|
|
```rust
|
|
|
|
// Host code
|
|
|
|
/* Rust API */
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Commands {
|
|
|
|
NameOne(name_one::NameOne),
|
|
|
|
}
|
|
|
|
pub mod name_one {
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum NameOne {
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
from_first_namespace,
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
from_second_namespace,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* C API */
|
|
|
|
pub mod name_one_c {}
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn name_one_from_first_namespace() -> core::ffi::c_int {
|
|
|
|
callback_function(name_one_from_first_namespace);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn name_one_from_second_namespace() -> core::ffi::c_int {
|
|
|
|
callback_function(name_one_from_second_namespace);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
// vim: filetype=rust
|
|
|
|
```
|
|
|
|
|
|
|
|
# Auxiliary files
|
2024-03-26 16:28:21 +00:00
|
|
|
|
2024-03-26 16:08:49 +00:00
|
|
|
File path: `dist/interface.h`
|
2024-03-26 16:28:21 +00:00
|
|
|
|
2024-03-26 16:08:49 +00:00
|
|
|
```c
|
|
|
|
#if !defined TRIXY_MAIN_HEADER
|
|
|
|
#define TRIXY_MAIN_HEADER
|
|
|
|
|
|
|
|
#include "errno.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "vec.h"
|
|
|
|
|
|
|
|
extern int name_one_from_first_namespace ();
|
|
|
|
|
|
|
|
extern int name_one_from_second_namespace ();
|
|
|
|
|
|
|
|
struct name_one
|
|
|
|
{
|
|
|
|
int (*from_first_namespace) (void);
|
|
|
|
int (*from_second_namespace) (void);
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct name_one name_one = {
|
|
|
|
.from_first_namespace = name_one_from_first_namespace,
|
|
|
|
.from_second_namespace = name_one_from_second_namespace,
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // if !defined TRIXY_MAIN_HEADER
|
|
|
|
// vim: filetype=c
|
|
|
|
```
|