matusnovak / wrenbind17

A header only library for binding C++17 classes and functions to Wren, an embeddable programming language
https://matusnovak.github.io/wrenbind17
MIT License
65 stars 10 forks source link

Unable to assign values to binded classes which has binded class members. #19

Closed mastercuber55 closed 1 year ago

mastercuber55 commented 1 year ago

I've a got a simpleVector2 struct consisting of x and y. I've binded it. Then I've got a more complex struct, Camera2D

typedef struct Camera2D {
    Vector2 offset;         // Camera offset (displacement from target)
    Vector2 target;         // Camera target (rotation and zoom origin)
    float rotation;         // Camera rotation in degrees
    float zoom;             // Camera zoom (scaling), should be 1.0f by default
} Camera2D;

I've also binded that too like

auto& Camera2DCls = RaylibMod.klass<Camera2D>("Camera2D");
Camera2DCls.ctor<>();
Camera2DCls.var<&Camera2D::offset>("offset");
Camera2DCls.var<&Camera2D::target>("target");
Camera2DCls.var<&Camera2D::rotation>("rotation");
Camera2DCls.var<&Camera2D::zoom>("zoom");

And I'm using it like this like following in wren side.

_Cam = Camera2D.new()

_Cam.offset.x = 1280 / 2
_Cam.offset.y = 768 / 2

System.print("Cam Offset: %(_Cam.offset.x), %(_Cam.offset.y)")

But no matter what I do, offest is always 0 for both x and y.

matusnovak commented 1 year ago

Hi @mastercuber55

Sorry for a late response.

This is indeed a bug in the library. Properties were returned as a copy. However this was an easy fix that hopefully does not break any backwards compatibility.

This is now fixed in a commit https://github.com/matusnovak/wrenbind17/commit/3255318670ce1b3ccbb9581559713ce79bc4b9a9 which is in the master branch as of now. Please pull from the master. I have added your example as part of the test suite.

Please report back if this has solved your problem.

mastercuber55 commented 1 year ago

Hi matusnovak, I don't mind the late response and as for the bug fixing, you've done a amazing job its totally working.

Thank you very much.