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:
parent
b5f5ae8b03
commit
645b8d58f6
|
@ -34,13 +34,12 @@ impl Function {
|
||||||
let inputs: Vec<TokenStream2> = self
|
let inputs: Vec<TokenStream2> = self
|
||||||
.inputs
|
.inputs
|
||||||
.iter()
|
.iter()
|
||||||
// FIXME(@soispha): This was `named_type_to_rust_trixy` <2024-03-25>
|
.map(NamedType::to_c)
|
||||||
.map(NamedType::to_rust)
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let callback_function = format_ident!("{}", config.callback_function);
|
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 {
|
if let Some(r#type) = &self.output {
|
||||||
let output_ident = r#type.to_c();
|
let output_ident = r#type.to_c();
|
||||||
|
@ -63,7 +62,7 @@ impl Function {
|
||||||
quote! {
|
quote! {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn #ident(#(#inputs),*) -> core::ffi::c_int {
|
pub extern "C" fn #ident(#(#inputs),*) -> core::ffi::c_int {
|
||||||
#callback_function (#command_value);
|
#callback_function (crate :: #command_value);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +108,7 @@ impl Function {
|
||||||
|
|
||||||
if namespaces.is_empty() {
|
if namespaces.is_empty() {
|
||||||
quote! {
|
quote! {
|
||||||
Commands:: #function_ident
|
Commands :: #function_ident
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let nasp_pascal_ident = namespaces.last().expect("We checked").to_rust_pascalized();
|
let nasp_pascal_ident = namespaces.last().expect("We checked").to_rust_pascalized();
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
use quote::quote;
|
use quote::{format_ident, quote};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
macros::config::trixy::TrixyConfig,
|
macros::config::trixy::TrixyConfig,
|
||||||
|
@ -46,13 +46,18 @@ impl Namespace {
|
||||||
.collect();
|
.collect();
|
||||||
let structures: TokenStream2 = self.structures.iter().map(Structure::to_c).collect();
|
let structures: TokenStream2 = self.structures.iter().map(Structure::to_c).collect();
|
||||||
let enumerations: TokenStream2 = self.enumerations.iter().map(Enumeration::to_c).collect();
|
let enumerations: TokenStream2 = self.enumerations.iter().map(Enumeration::to_c).collect();
|
||||||
|
|
||||||
|
let callback_function = format_ident!("{}", config.callback_function);
|
||||||
quote! {
|
quote! {
|
||||||
pub mod #ident {
|
pub mod #ident {
|
||||||
|
#[allow(unused_imports)]
|
||||||
|
use crate :: #callback_function;
|
||||||
|
|
||||||
#enumerations
|
#enumerations
|
||||||
#structures
|
#structures
|
||||||
|
#additional_functions
|
||||||
}
|
}
|
||||||
#functions
|
#functions
|
||||||
#additional_functions
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,20 +33,13 @@ impl NamedType {
|
||||||
#ident : #r#type
|
#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 {
|
pub fn to_rust_assignment(&self) -> TokenStream2 {
|
||||||
let ident = self.name.to_rust();
|
let ident = self.name.to_rust();
|
||||||
quote! {
|
quote! {
|
||||||
#ident : match #ident.try_into() {
|
#ident : match #ident.try_into() {
|
||||||
Ok(ok) => ok,
|
Ok(ok) => ok,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
trixy::types::traits::errno::set(err);
|
trixy::types::traits::errno::set(err.into());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue