Page 1 of 1

Passing objects with Luabind

Posted: Sun Mar 22, 2009 10:38 am
by K-Bal
Hey guys,

I have a class for managing images and allocating memory for them.

I already know how to export this class to lua with luabind, so I can create one in a lua script, but I don't really know how to pass an existing instance of this class to lua.

I read the documentation two times but I didn't really see a solution to this. Maybe I'm just blind or I misunderstood something.

Cheers,
Marius

Re: Passing objects with Luabind

Posted: Sun Mar 22, 2009 1:08 pm
by Ginto8
One solution, if there's only one instance of the class, use M_D_K's "Singleton" method (which doesn't follor singleton theory, but works anyway :lol: ). I'd send you the code, but it's on another computer, so ask him for it. ;) :mrgreen:

Re: Passing objects with Luabind

Posted: Sun Mar 22, 2009 2:04 pm
by K-Bal
You mean you provide a GetInstance function that can be called in C++ and in Lua?

If it's really that simple I guess I could code it myself. ;)

Re: Passing objects with Luabind

Posted: Sun Mar 22, 2009 7:39 pm
by M_D_K
WTF Ginto!
The idea behind a Singleton is there is only one, just cause I wasn't stupid enough to initiate a singleton based class more than once doesn't mean that its not a singleton. BTW the singleton class I gave you allows for easy creation of singletons, its the programmer that has to follow the theory(which you didn't :See last sentence).

Re: Passing objects with Luabind

Posted: Sun Mar 22, 2009 9:00 pm
by Ginto8
M_D_K wrote:WTF Ginto!
The idea behind a Singleton is there is only one, just cause I wasn't stupid enough to initiate a singleton based class more than once doesn't mean that its not a singleton. BTW the singleton class I gave you allows for easy creation of singletons, its the programmer that has to follow the theory(which you didn't :See last sentence).
Ok, sorry. I guess I was saying it the wrong way. What I meant is that it does not fit the most common implementation of a singleton. And I DO follow the theory! When did I ever try to initiate a singleton more than once???? when I first mentioned its non-conventionality, I was basing what I said on its design. Most programmers don't seem to trust themselves enough to use your type of singleton I guess. :lol:

Re: Passing objects with Luabind

Posted: Sun Mar 22, 2009 10:18 pm
by Falco Girgis
Yeah, all that you want to do is return a reference with a getInstance. The fact that its a singleton really doesn't have anything to do with the implementation. XD

Re: Passing objects with Luabind

Posted: Mon Mar 23, 2009 5:53 am
by K-Bal
Okay, thank you guys, sounds easy.

I can't believe that they don't say a word in the documentation about such a basic thing.

Re: Passing objects with Luabind

Posted: Mon Mar 23, 2009 7:09 am
by K-Bal
GyroVorbis wrote:Yeah, all that you want to do is return a reference with a getInstance. The fact that its a singleton really doesn't have anything to do with the implementation. XD
Do you mean a C++ reference or a boost.reference?

OT: Since I've registered on the board I'm asking myself what you want to imply with your avatar :lol: :lol: