How to bind member function like A::get_data(double & value)
Hi, I am new to LuaBridge. I read all the docs but fail to find ways to register such function with basic type reference.
My C++ class has a member function:
class CData { public: void get_data(int index, double &val); }
I tried to use the following, addFunction("get_data", &CData::get_data) but it failed to comile with en error: luabridge\detail\typelist.h(212): error C2664: “luabridge::TypeListValues<Tail>::TypeListValues(luabridge::TypeListValues<Tail> &&)”: cannot convert parameter 1 from “double” to “Head &”
How to bind such kinds of member function?
So you expect this should work:
luabridge::getGlobalNamespace (L)
.beginClass <CData> ("Int")
.addFunction ("get_data", &CData::get_data)
.endClass ();
... but it doesn't because there is an L-value reference parameter.
LuaBridge doesn't support references and pointers for simple types (as well as Lua).
I'd suggest you using double get_data(int index) in your class.
Is your issue solved?
you should be able, by slighly modifying the behaviour of the scripted function like this:
luabridge::getGlobalNamespace (L)
.beginClass <CData> ("Int")
.addFunction ("get_data", +[](const CData* thiz, int i) { double v; thiz->get_data(i, v}; return v; })
.endClass ();
is it feasible for you ?
luabridge can't support references for trivial types because is lua that doesn't support them in the language, so you can only work it around by passing tables (tables are passed by referenca in lua) so you need to place your double in a table.