Pass a pointer to an object to lua

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
User avatar
mv2112
Chaos Rift Junior
Chaos Rift Junior
Posts: 240
Joined: Sat Feb 20, 2010 4:15 am
Current Project: Java Tower Defence Game
Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
Programming Language of Choice: C/++, Java
Location: /usr/home/mv2112
Contact:

Pass a pointer to an object to lua

Post by mv2112 »

How do you pass a pointer of an instance of an object to Lua?

Code: Select all

Object_Cont=mvGetObjectController() --something like this would return a pointer to the object system from the engine
i=Object_Cont:mvAddItem("heart")
Object_Cont:mvItemPos(i,400,400)
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: Pass a pointer to an object to lua

Post by Ginto8 »

mv2112 wrote:How do you pass a pointer of an instance of an object to Lua?

Code: Select all

Object_Cont=mvGetObjectController() --something like this would return a pointer to the object system from the engine
i=Object_Cont:mvAddItem("heart")
Object_Cont:mvItemPos(i,400,400)
That looks like it should work, but you might want to make it that mvGetObjectController() or whatever the function will be called returns a reference, that way it definitely will work. I believe that this is how the ES lua engine used to work.
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: Pass a pointer to an object to lua

Post by Falco Girgis »

That would work assuming that you had some sort of way to pass a reference to the Lua stack. For us, that's toLua++.

I'm assuming you don't want to be a hero or hardcore here (because it's more tedious than anything). Look into toLua++, Swig, and LuaBind.
User avatar
mv2112
Chaos Rift Junior
Chaos Rift Junior
Posts: 240
Joined: Sat Feb 20, 2010 4:15 am
Current Project: Java Tower Defence Game
Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
Programming Language of Choice: C/++, Java
Location: /usr/home/mv2112
Contact:

Re: Pass a pointer to an object to lua

Post by mv2112 »

I actually just got toLua++ and compiled it yesterday. I'm gonna have to read up on the lua stack.
User avatar
mv2112
Chaos Rift Junior
Chaos Rift Junior
Posts: 240
Joined: Sat Feb 20, 2010 4:15 am
Current Project: Java Tower Defence Game
Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
Programming Language of Choice: C/++, Java
Location: /usr/home/mv2112
Contact:

Re: Pass a pointer to an object to lua

Post by mv2112 »

I cant figure out how to pass an object reference to the lua stack. :x How would you do it with tolua++? All i've done so far was bind the class to lua. Im stumped :|

EDIT:
I was able to create functions that access the object by defining the item system object as global.
Post Reply