LuaBridge
LuaBridge copied to clipboard
static const class member support?
current use addStaticProperty will get error, so how to bind class static const member to Lua?
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*/ });
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. assumingconst 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#?