Skip to content

Register properties without getter/setter #29

@totalgee

Description

@totalgee

It would be nice to be able to expose member variables of a class without needing a getter/setter in the class.

// Assuming we have a vec3 class/struct with public member `x`, like this:
struct vec3 {
    float x{};
    float y{};
    float z{};
};

// It would be nice to be able to register the property using:
    dukglue_register_property(ctx, &vec3::x, "x");

An alternative would be to support this by letting the getter/setter method be a free function (or lambda), rather than a class method. That way, even if you couldn't expose the member directly, as shown above, you could create getter/setter without modifying the class, using lambdas:

    dukglue_register_property(ctx,
        [](vec3 const& v) { return v.x; }, // getter lambda
        [](vec3& v, float new_x) { v.x = new_x; }, // setter lambda
        "x");

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