Now we call the function from Lua:
local m = MyStruct() local x = MyMember() foo(m, x)
It seems correct at first, but the API is flawed. Parameter x might get altered if function is used as follows:
local m = MyStruct() m.x = 3 foo(m, m.x)
Expected value of m.x: 4 Actual value of m.x: 2
What is the best practice to avoid this 'fake-const' problem?
I understand you can change the signature of foo to "void foo(MyStruct &m, MyMember x)", but that implies a possible performance hit, doesn't it? Is there a better way?
My feeling is that all bound functions should have non-reference parameters IF parameter type exists in 'this' AND is bound to lua. Correct? Is it possible that luabind could handle this automatically to avoid semantic errors?