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

Static variables aren't updated. #1416

Open
deadlocklogic opened this issue Oct 27, 2022 · 3 comments
Open

Static variables aren't updated. #1416

deadlocklogic opened this issue Oct 27, 2022 · 3 comments

Comments

@deadlocklogic
Copy link
Contributor

deadlocklogic commented Oct 27, 2022

Lua: 5.1
Sol2: latest

C++ side:

struct MyStruct {
    static int variable;
    static int getVariable() {
        return variable;
    }
};
int MyStruct::variable = 3;

Binding:

auto _cppbind_MyStruct = state.new_usertype<::MyStruct>(
    "MyStruct",
    "getVariable", &::MyStruct::getVariable,
    "variable", sol::var(std::ref(::MyStruct::variable))
);

Lua side:

print(MyStruct.variable) -- 3
print(MyStruct.getVariable()) -- 3
MyStruct.variable = 123
print(MyStruct.variable) -- 123
print(MyStruct.getVariable()) -- 3??? expected 123

Do I need to use a property instead?

Edit: even using a property isn't calling the setter.

@deadlocklogic deadlocklogic changed the title Global values can't be updated correctly. Static variables aren't updated. Oct 27, 2022
@Smertig
Copy link
Contributor

Smertig commented Oct 27, 2022

Looks like a duplicate of #1268

@deadlocklogic
Copy link
Contributor Author

Yes apparently, did you manage to work around this issue because its still open from 2021?
Such fundamental things breaking are worrying after investing too much time with this good library. The problem is that there is virtually only one maintainer who knows all the nitpicks but apparently busy nowadays.

@Smertig
Copy link
Contributor

Smertig commented Oct 28, 2022

I didn't find any workaround. I just replaced static properties with getter/setter, that is ugly but working solution.

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