Replies: 4 comments
-
You can try to use mlua scope functionality without leaking memory: let mut string_object = String::from("Hello, world!");
let func = lua.create_function(|_, mut obj: mlua::UserDataRefMut<String>| {
*obj = "Hello from Rust".to_string();
Ok(())
})?;
lua.scope(|scope| {
let mut_obj = scope.create_any_userdata_ref_mut(&mut string_object);
func.call::<_, ()>(mut_obj)
})?;
// prints: Hello from Rust
println!("{}", string_object); Mutable reference to object ( I hope the approach above would work for you as it was designed for such cases. |
Beta Was this translation helpful? Give feedback.
-
So the problem here is that I need to create a wrapper around a mutable type. I'm binding things from a crate I didn't make - rapier2d. So I have |
Beta Was this translation helpful? Give feedback.
-
Do you have Discord, perchance? |
Beta Was this translation helpful? Give feedback.
-
You don't need a wrapper. v0.9 has new api for "any" userdata which allow interaction with objects defined in another crates. Also the requirement |
Beta Was this translation helpful? Give feedback.
-
I'm sorry if this is a newbie question but I've been at this for hours and have tried too many things to name honestly. I am currently on 0.9.0 beta 2.
Beta Was this translation helpful? Give feedback.
All reactions