-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Description
It would be really nice if rlua
provided a macro that allowed declaring methods via add_method
and add_method_mut
on UserData
in a simpler way.
Something like:
#[rlua::proc_methods]
impl UserData for MyStruct {
// ... actual UserData methods ...
#[rlua::method]
fn methodA<'lua>(&self, abc: LuaContext<'lua>, number: f32, text: String) {
// same as: methods.add_method("methodA", |abc, _self, (number, text): (f32, String)| { /*block*/ })
}
#[rlua::method]
fn methodB<'lua>(&mut self, cde: LuaContext<'lua>, other_number: f32, some_text: String) {
// same as: methods.add_method_mut("methodB", |cde, _self, (other_number, some_text): (f32, String)| { /*block*/ })
}
}
This is quite involved to implement. Note that _self
handling requires modification of the inner code block, but syn
has a visit-mut
feature for precisely this functionality.
Benefits
- Resulting API would be 10x nicer looking.
- Types could be checked using generated glue that throws very specific error messages containing exact names of parameters which failed.
Alternative proposal
A normal macro that wraps individual add_method
calls would still allow generating more specific error messages while avoiding separation of argument names and types in callback signature.
jugglerchris
Metadata
Metadata
Assignees
Labels
No labels