Sign in to follow this  
Escarab

luabind - using object pointers

Recommended Posts

Lua is getting more complicated as I go deeper in it. I cant do a simple thing. I want to pass a pointer to a object to a lua function and call a member function through that pointer. something like...

...
luabind::module(luaVM)
    [
    luabind::class_<CClientBase>("ClientBase"),
    luabind::class_<CClientContext,CClientBase>("ClientContext")
      .def(luabind::constructor<>())
      .def("Drop", &CClientContext::Drop)
     ];
...

void func(CClietContext* c)
{
luabind::call_function<void>(luaVM, "WorkerCall",c);
}


where the script is something like this function WorkerCall(client) client:Drop() end Obviously, this is not working, otherwise I wouldn't be here asking. This crashes badly on me. How do I do it correctly?

Share this post


Link to post
Share on other sites
I don't know if Luabind does this but Mluabind, the syntax for executing method on bound objects uses the . notation not the : notation.

so your Lua function would be something like this:

function WorkerCall(client)
client.Drop()
end

The : notation dispatches with the self parameter as the first parameter in the function call, which only works for native Lua classes, bound objects are implemented as a single table where method calls are dispatched with associated light user data corresponding to the native ptr, this is how Mluabind works.

I suspect Luabind works simialrly. Give it a try!

Good Luck!

-ddn

Share this post


Link to post
Share on other sites
I did it, i did it [grin]!! It was that simple as I though.

Apparently I've compiled luabind wrong (what is not that difficult, download, boost, set the path boost_ROOT, compile boost, download bjam...), or version 0.7.1 just sucks.

The fact is, I downloaded a precompiled version from here and every think just starts to work now.
But, at list with vc++08 compiler, you need to /NODEFAULTLIB:MVCRT if you want to compile something.Till now, I was unable to compile it in debug, but I'm working on it.

Share this post


Link to post
Share on other sites
Funny thing, i can only compile with /GL option(relinking optimization) otherwise it gives me a bunch of errors like:

<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in main.obj
msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::operator+=(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@ABV01@@Z) already defined in main.obj


it is just a sample, there is a lot more from where this came from.
Any one knows why this is happening?

Share this post


Link to post
Share on other sites
MSVCP90.dll is the runtime dll for release versions, which is different from the debug version used for debug builds, which is proably MSVCP90d.dll given the naming convetion. The library your linking with is proably a release version, you'll need to link with the debug version if you want to compile the debug verison. Given the naming convention most used, the debug library will be the same name plus a d suffix, ie luabind.lib -> luabindd.lib etc.. If your using precompiled versions, there should be both release and debug versions available.

Good Luck!

-ddn


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this