Skip to content

Pass userdata object as argument to __gc function? #43

@bit-garden

Description

@bit-garden

I'm currently working with Raylib which is written in C. It relies on the developer to manually unload resources.

In the example of Texture2d, I would like to define __gc to clean it up automatically when used from Lua, but the reference to the userdata object gets lost.

Example:

luaTexture2d.def("__gc", [](Texture2d& self){ unloadTexture(self);});

__gc is not called in this case unless no arguments are passed.

Unless I'm missing something. I would have to add a GC function to the struct and then bind it that way, but this would break on upstream updates.

I also tried adding the destructor through the .ctor function but this throws a type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions