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 const class member support? #297

Open
spartawhy117 opened this issue Sep 14, 2022 · 2 comments
Open

static const class member support? #297

spartawhy117 opened this issue Sep 14, 2022 · 2 comments

Comments

@spartawhy117
Copy link

spartawhy117 commented Sep 14, 2022

current use addStaticProperty will get error, so how to bind class static const member to Lua?

@dmitry-t
Copy link
Collaborator

Indeed, such function is missing.
addStaticProperty() either requires a non-const member or both getter and setter.
As a workaround you can currently register a setter that does nothing or throws.
E.g. assuming const MyConstStaticDataType MyClass:constStaticData:

luabridge::getGlobalNamespace(L)
    .beginClass<MyClass>("MyClass")
    .addStaticProperty(
        "staticProperty",
        +[] { return MyClass::constStaticData; },
        +[](MyConstStaticDataType) { /*or throw here*/ });

@spartawhy117
Copy link
Author

Indeed, such function is missing. addStaticProperty() either requires a non-const member or both getter and setter. As a workaround you can currently register a setter that does nothing or throws. E.g. assuming const MyConstStaticDataType MyClass:constStaticData:

luabridge::getGlobalNamespace(L)
    .beginClass<MyClass>("MyClass")
    .addStaticProperty(
        "staticProperty",
        +[] { return MyClass::constStaticData; },
        +[](MyConstStaticDataType) { /*or throw here*/ });

if someone write in Lua like this

      local constData = MyClass.constStaticData
      constData = new value

     ... other code
     local dir =MyClass.constStaticData * other value

the first one want to modify the const value will get error? and the second one use that var is still default value in c#?

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