mlua
mlua copied to clipboard
Lifetime Issues with Scope
Some trivially valid examples are currently impossible due to lifetime annotations:
// This works fine
let mut i = 0;
lua.scope(|scope| {
scope.create_any_userdata_ref_mut(&mut i);
});
// This fails because the type must be 'static
struct Wrapper<'a>(&'a mut i32);
let mut w = Wrapper(&mut i);
lua.scope(|scope| {
scope.create_any_userdata_ref_mut(&mut w)
});
scope.create_any_userdata_ref_mut
should not require T: 'static
. The only workaround I've found is to transmute the parameter.
Try Scope::create_nonstatic_userdata
. It's slower alternative that does not require T: 'static
.
That does work, but creating a new metaclass for almost every single function call is not a tenable situation.
Unfortunately non-'static
types don't implement Any
trait which is the main blocker.