fix(macros/generate/host/c/function): Actually call the callback function

Previously, the generated c wrapper function did not call the callback
correctly.
This commit is contained in:
Benedikt Peetz 2024-03-27 22:11:12 +01:00
parent b5f5ae8b03
commit 645b8d58f6
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
3 changed files with 12 additions and 15 deletions

View File

@ -34,13 +34,12 @@ impl Function {
let inputs: Vec<TokenStream2> = self
.inputs
.iter()
// FIXME(@soispha): This was `named_type_to_rust_trixy` <2024-03-25>
.map(NamedType::to_rust)
.map(NamedType::to_c)
.collect();
let callback_function = format_ident!("{}", config.callback_function);
let command_value: TokenStream2 = self.identifier.to_c_with_path(&namespaces);
let command_value: TokenStream2 = self.to_rust_path(&namespaces);
if let Some(r#type) = &self.output {
let output_ident = r#type.to_c();
@ -63,7 +62,7 @@ impl Function {
quote! {
#[no_mangle]
pub extern "C" fn #ident(#(#inputs),*) -> core::ffi::c_int {
#callback_function (#command_value);
#callback_function (crate :: #command_value);
return 1;
}
}
@ -109,7 +108,7 @@ impl Function {
if namespaces.is_empty() {
quote! {
Commands:: #function_ident
Commands :: #function_ident
}
} else {
let nasp_pascal_ident = namespaces.last().expect("We checked").to_rust_pascalized();

View File

@ -21,7 +21,7 @@
*/
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use quote::{format_ident, quote};
use crate::{
macros::config::trixy::TrixyConfig,
@ -46,13 +46,18 @@ impl Namespace {
.collect();
let structures: TokenStream2 = self.structures.iter().map(Structure::to_c).collect();
let enumerations: TokenStream2 = self.enumerations.iter().map(Enumeration::to_c).collect();
let callback_function = format_ident!("{}", config.callback_function);
quote! {
pub mod #ident {
#[allow(unused_imports)]
use crate :: #callback_function;
#enumerations
#structures
#additional_functions
}
#functions
#additional_functions
}
}
}

View File

@ -33,20 +33,13 @@ impl NamedType {
#ident : #r#type
}
}
pub fn to_rust_c_assignment(&self) -> TokenStream2 {
let ident = self.name.to_rust();
let type_ident = self.r#type.to_c();
quote! {
#ident : #type_ident
}
}
pub fn to_rust_assignment(&self) -> TokenStream2 {
let ident = self.name.to_rust();
quote! {
#ident : match #ident.try_into() {
Ok(ok) => ok,
Err(err) => {
trixy::types::traits::errno::set(err);
trixy::types::traits::errno::set(err.into());
return 0;
}
}