Skip to content

Commit

Permalink
Fix compiler errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MavethGH committed Jan 20, 2024
1 parent 9a44f13 commit a06049e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions codegen/src/custom_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub fn derive_custom_type_impl(input: DeriveInput) -> TokenStream {

quote! {
impl ::rhai::CustomType for #name {
fn build(builder: ::rhai::TypeBuilder<'_, Self>) {
#accessors
fn build(mut builder: ::rhai::TypeBuilder<'_, Self>) {
#accessors;
}
}
}
Expand All @@ -63,11 +63,11 @@ fn generate_accessor_fns(
) -> proc_macro2::TokenStream {
let get = get
.map(|func| quote! {#func})
.unwrap_or_else(|| quote! {|obj| obj.#field.clone()});
.unwrap_or_else(|| quote! {|obj: &mut Self| obj.#field.clone()});

let set = set
.map(|func| quote! {#func})
.unwrap_or_else(|| quote! {|obj, val| obj.#field = val});
.unwrap_or_else(|| quote! {|obj: &mut Self, val| obj.#field = val});

if readonly {
quote! {
Expand Down
15 changes: 15 additions & 0 deletions codegen/tests/test_derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use rhai_codegen::CustomType;

// Sanity check to make sure everything compiles
#[derive(Clone, CustomType)]
pub struct Foo {
#[get(get_bar)]
bar: i32,
#[readonly]
baz: String,
qux: Vec<i32>,
}

fn get_bar(_this: &mut Foo) -> i32 {
42
}

0 comments on commit a06049e

Please sign in to comment.