   [LUA][Luabind] Passing class-references to lua not working [SOLVED]
  Hey there,I am using LUA and Luabind. So far, using C++ function with various parameters in lua has worked quite well and is already integrated into our project.The next step would be passing references to c++-Objects to a lua function for further "manipulation".Here is my main cpp:extern "C" int init(lua_State* L){    using namespace luabind;    open(L);    module(L)    [   def("greet", &greet),class_<CMyTest>("Testclass").def(constructor   < > ()).def("setTest", &CMyTest::setTest)//.property("iTest", &CMyTest::setTest, &CMyTest::getTest)    ];    return 0;}int _tmain(int argc, _TCHAR* argv[]){lua_State* pState = lua_open();init(pState);CMyTest xTest;luaL_dofile(pState, "ScriptTest.lua");luabind::call_function<void>(pState, "Start", boost::ref(xTest));lua_close(pState);return 0;}Here is my script file:function Start(obj)obj.setTest(5894)endThe CMyTest class only has one private member and a getter and setter method for that one. Nothing else.Now... with both the .property and the .def-implementation, I get a crash ("luabind::error at memory location...") at this part of the call_function.hpp of luabind:~proxy_function_void_caller(){...// pops the return values from the function callstack_pop pop(L, lua_gettop(L) - top + m_params); <--- Error Line}And yes, the file does exist and can be loaded correctly. I already tried out other functions in it, etc.But I really have no idea how to solve this problem... or, to be more precisely, I have no idea what the problem is.[Edited by - TheSHEEEP on April 18, 2010 11:20:53 AM]
  figuring out what the problem is can often be hard with lua. You could try looking into getting the exceptions working, would help you debugging (I never did though). I have this small bit of code that has helped me occasionally but it rarely gets hit when I do have a problem, still work a try:catch(luabind::error& e){std::string error = lua_tostring( e.state(), -1 );// Do somehting with it}it has given me something meaninful a few times. I guess with your code, luabind doensn't know what a boost::ref is, could you pass as a pointer instead?   ;  Thanks for your advice.I didn't think about catching that error. Never used try/catch before (it's just not the usual way in gaming business, it seems). It indeed gave me something:Quote:No matching overload found, candidates:void setTest(CMyClass&, int)Now I'm not exactly sure what to make of that. I did register the class and the function.Though the function I created of course does not look like "setTest(CMyClass&, int)". It looks like "setTest(int)".Do I have to create a function that does have a reference to the class as the first parameter? Isn't that the job of luabind?Using the .property instead of the .def results in this error:Quote:No matching overload found, candidates:int <unknown>(CMyTest const&)Also, it doesn't make a difference if I use boost::ref or not. using boost::ref also is the way it is done in the luabind documentation.[Edited by - TheSHEEEP on April 18, 2010 8:43:36 AM];  In lua; obj.stuff(1234) attempts to index obj to find an element called 'stuff' and attempts to call it with only the argument 1234. In your example, you would be calling the equivalent of Testclass::stuff(5894), which is missing the 'this' pointer.You want to do obj:stuff(5894) (notice the : instead of ., which is lua syntax sugar for obj.stuff(obj, 5894)).;  Oh well, I really didn't know that.Thanks, that solved my problem!   