luabind - using object pointers

This topic is 3616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 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 on other sites
I don't think that's the case. in Luabind, classes are represented as userdata.

Share on other sites
What is the error that luabind spits out?

Share on other sites
The very useful and descriptive error is: "lua runtime error"

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 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 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

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• Forum Statistics

• Total Topics
632948
• Total Posts
3009410
• Who's Online (See full list)

There are no registered users currently online

×