Skip to content

Commit

Permalink
codegen: Update wrapper creation to handle return values
Browse files Browse the repository at this point in the history
  • Loading branch information
C47D committed Jan 12, 2025
1 parent 382d3eb commit e0085b4
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lvgl-codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,29 @@ impl Rusty for LvFunc {
}
});

// TODO: Handle methods that return types
// NOTE: When the function returns something we can 'avoid' placing an Ok()
// at the end.
let return_ok_at_the_end = if return_type.is_empty() {
quote!(Ok(()))
} else {
quote!()
};

// And we can also return from the unsafe block by removing the ; at the end
let implicit_return = if has_return_value {
quote!()
} else {
quote!(;)
};

Ok(quote! {
pub fn #func_name(#args_decl) -> crate::LvResult<()> {
pub fn #func_name(#args_decl) -> #return_type {
#args_processing
unsafe {
lvgl_sys::#original_func_name(#args_call);
lvgl_sys::#original_func_name(#args_call)#implicit_return
}
Ok(())

#return_ok_at_the_end
}
})
}
Expand Down

0 comments on commit e0085b4

Please sign in to comment.