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

Cannot modify static sol::property from lua #1268

Open
Smertig opened this issue Nov 3, 2021 · 0 comments
Open

Cannot modify static sol::property from lua #1268

Smertig opened this issue Nov 3, 2021 · 0 comments

Comments

@Smertig
Copy link
Contributor

Smertig commented Nov 3, 2021

Consider the following:

#include <sol/sol.hpp>

#include <cassert>

struct X {
    static inline int v = 1;

    static void set_var(int value) {
        X::v = value;
    }

    static int get_var() {
        return X::v;
    }
};

int main() {
    std::printf("sol: %s\n", SOL_VERSION_STRING);

    sol::state L;
    L.open_libraries();

    auto x = L.new_usertype<X>("X");
    x["v"] = sol::property(&X::set_var, X::get_var);

    // value == 1?
    L.safe_script("assert(X.v == 1)");
    assert(X::v == 1);

    // modify from cpp..
    X::v = 2;

    // value == 2?
    L.safe_script("assert(X.v == 2)");
    assert(X::v == 2);

    // modify from lua..
    L.safe_script("X.v = 3");

    // value == 3?
    L.safe_script("assert(X.v == 3)");
    assert(X::v == 3); // BOOM
}

Note, that last assertion fails.

I think it's similar to #1267

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

1 participant