mlua
mlua copied to clipboard
Mix `UserData` and serde fields automatically.
I have something like this
#[derive(Serialize, Deserialize, Clone)]
pub struct Uri {
scheme: Option<String>,
authority: Option<Authority>,
path: String,
query: Option<String>,
}
impl UserData for Uri {
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_method("tostring", |_, this, ()| {
let uri: http::Result<hyper::Uri> = this.to_owned().into();
Ok(uri.to_lua_err()?.to_string())
})
}
}
I'm facing an issue where I want lua to be able to access all the fields on Uri while also being able to access UserData methods.
I've attempted using create_ser_userdata which gives me access to UserData but prevents me from accessing the fields once again. Upon re-serializing the object made with create_ser_userdata I still see the proper fields present.
Is there a way to mix and match UserData and regular fields in a serializable struct?
so you basically want a Derive macro for add_fields
so that you dont have to write the add_fields function yourself