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

Register properties without getter/setter #29

Open
totalgee opened this issue Feb 13, 2022 · 1 comment
Open

Register properties without getter/setter #29

totalgee opened this issue Feb 13, 2022 · 1 comment

Comments

@totalgee
Copy link

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");
@Wolfleader101
Copy link

Any update on getting this working?

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

2 participants