$ /usr/bin/c++ --version
c++ (GCC) 14.1.1 20240522
Workaround
There can be many workarounds. The two I am interested in are
Workaround 1
Make two lua bindings for same C++ class MyClass lets call one LMyClass and the other CLMyClass. The CLMyClass will not expose bind any non-const member functions. It will bind the mutable member variables a const properties using sol::readonly.
But the problem with this approach is How will I decide when it should use CLMyClass instead of LMyClass?
Then provide make two lua user types for type<X, true> and type<X, false> . The problem with this approach is, if class X has a member variable of type std::vector it has to be transformed to std::vector<type<Y, Const>> which is very difficult to do automatically without any usercode.
C++ arguments of
sol::protected_function
looses const-ness. The non-const functions of the C++ class can be called from the lua function.Minimal reproducible example
Compiler:
$ /usr/bin/c++ --version c++ (GCC) 14.1.1 20240522
Workaround
There can be many workarounds. The two I am interested in are
Workaround 1
Make two lua bindings for same C++ class
MyClass
lets call oneLMyClass
and the otherCLMyClass
. The CLMyClass will not expose bind any non-const member functions. It will bind the mutable member variables a const properties usingsol::readonly
.But the problem with this approach is How will I decide when it should use CLMyClass instead of LMyClass?
Workaround 2
I am trying to workaround it in a different way.
Then provide make two lua user types for it has to be transformed to std::vector<type<Y, Const>> which is very difficult to do automatically without any usercode.
type<X, true>
andtype<X, false>
. The problem with this approach is, if class X has a member variable of type std::vector