diff --git a/src/macros/generate/convert/auxiliary/c/identifier/mod.rs b/src/macros/generate/convert/auxiliary/c/identifier/mod.rs index c3844a5..a48de27 100644 --- a/src/macros/generate/convert/auxiliary/c/identifier/mod.rs +++ b/src/macros/generate/convert/auxiliary/c/identifier/mod.rs @@ -52,6 +52,23 @@ impl Identifier { const char* } } + // Unsigned + "u_8" => quote! { uint8_t }, + "u_16" => quote! { uint16_t }, + "u_32" => quote! { uint32_t }, + "u_64" => quote! { uint64_t }, + // Signed + "i_8" => quote! { int8_t }, + "i_16" => quote! { int16_t }, + "i_32" => quote! { int32_t }, + "i_64" => quote! { int64_t }, + // Float + "f_32" => quote! { float }, + "f_64" => quote! { double }, + // Other (not yet imlemented) + // ("Option", 1), + // ("Vec", 1), + // ("Result", 2), other => { todo!("'{}' is not yet supported", other) } diff --git a/src/macros/generate/convert/host/rust/type/mod.rs b/src/macros/generate/convert/host/rust/type/mod.rs index bf5f9b4..6c274c1 100644 --- a/src/macros/generate/convert/host/rust/type/mod.rs +++ b/src/macros/generate/convert/host/rust/type/mod.rs @@ -42,7 +42,11 @@ impl Type { } } pub fn to_rust_function(inputs: &[NamedType], output: &Option>) -> TokenStream2 { - let inputs: Vec = inputs.iter().map(NamedType::to_rust).collect(); + let inputs: Vec = inputs + .iter() + .map(|r#type| &r#type.r#type) + .map(Type::to_rust) + .collect(); let output = if let Some(output) = output { let output = output.to_rust(); quote! { diff --git a/tests/functions/expected.md b/tests/functions/expected.md index e69de29..aa97a82 100644 --- a/tests/functions/expected.md +++ b/tests/functions/expected.md @@ -0,0 +1,74 @@ +# 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" + +/** + Call out an outstanding person +*/ +extern int +call_me_back_outstanding (const char *(*name) (const char *name)callback); + +/** + Call out a person +*/ +extern int one_call_me_back (void (*name) (uint32_t age) callback); + +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 +```