Page 1 of 1

Pass a pointer to an object to lua

Posted: Mon Apr 12, 2010 7:04 pm
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)

Re: Pass a pointer to an object to lua

Posted: Tue Apr 13, 2010 7:42 am
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.

Re: Pass a pointer to an object to lua

Posted: Tue Apr 13, 2010 7:51 am
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.

Re: Pass a pointer to an object to lua

Posted: Tue Apr 13, 2010 1:46 pm
by mv2112
I actually just got toLua++ and compiled it yesterday. I'm gonna have to read up on the lua stack.

Re: Pass a pointer to an object to lua

Posted: Tue Apr 13, 2010 8:45 pm
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.