Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Scope::new to allow finer control over objects lifetimes #329

Open
buffet opened this issue Nov 15, 2023 · 0 comments
Open

Expose Scope::new to allow finer control over objects lifetimes #329

buffet opened this issue Nov 15, 2023 · 0 comments

Comments

@buffet
Copy link

buffet commented Nov 15, 2023

I have a struct with a few members I am also exposing in my Lua API.

At the moment I wrap the struct member in an Rc, though this is technically incorrect since wgpu safety requires my window to outlive surfaces.

struct Example {
    foo: Foo,
    bar: Bar, // must outlive foo
}

I think something like this would be quite nice:

struct Example {
    scope: mlua::Scope,
    foo: Foo,
    bar: Bar, // must outlive foo and scope
}

lua.register_userdata_type::<EventLoopWindowTarget<()>>(|reg| {
    reg.add_field_method_get("foo", |_, this| {
        this.scope.create_any_userdata_ref(&this.foo)
    });
})?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant