Passing objects with Luabind

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Passing objects with Luabind

Post 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
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Passing objects with Luabind

Post 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:
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Passing objects with Luabind

Post 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. ;)
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: Passing objects with Luabind

Post 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).
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Passing objects with Luabind

Post 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:
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Passing objects with Luabind

Post 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
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Passing objects with Luabind

Post 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.
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Passing objects with Luabind

Post 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:
Post Reply