You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 12, 2025. It is now read-only.
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]implUserDataforMyStruct{// ... actual UserData methods ...#[rlua::method]fnmethodA<'lua>(&self,abc:LuaContext<'lua>,number:f32,text:String){// same as: methods.add_method("methodA", |abc, _self, (number, text): (f32, String)| { /*block*/ })}#[rlua::method]fnmethodB<'lua>(&mutself,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.