Skip to content

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

Closed as not planned
@buffet

Description

@buffet

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)
    });
})?;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions