lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


ah, yep, I understand now.
I was simulating this by calling a c function that had a pointer to the
object I wanted as a closure, then the function would call the appropriate
object member using the pointer passed in.
Great.  Thanks guys.

----- Original Message -----
From: "Terence Martin" <odat@telus.net>
To: "Multiple recipients of list" <lua-l@tecgraf.puc-rio.br>
Sent: Monday, June 17, 2002 6:04 PM
Subject: Re: C++ creation of object, and Lua co-calling


> I think the gist here is that the static member variable doesn't have an
> implicit "this" paramter passed to it. So the lua interpreter can call it
> like it would any other lua C function, if it has the right prototype. But
> the magic is that by using the ":" syntax, like myobject:mymethod () , the
> first parameter passed to the lua function is myobject. Which is your
> wrapped C++ object as a userdata. So you can fetch that off the lua stack,
> and use it to access the object all you want. It effectively becomes the
> "this" parameter that you didn't get because you're static.
>
> ----- Original Message -----
>
> > What's the advantage of using this method over exposing straight
> functions?
> > Or have I got something very wrong?
> > A static member function can't access the variables within a class, so
> with
> > my limited understanding this doesn't seem to help expose the methods of
> the
> > c++ object?
> > I do rather think I am wrong though :).
> >
> > > I think this answers the question you're asking:
> > >
> > > The C++ function you make available to Lua must be a static member
> > function.
> > > I really should have mentioned this. In Lua, I call the function using
> the
> > :
> > > operation, so it sticks a copy of the object on the stack. From that I
> > grab
> > > the ID, and that allows me to get at the C++ object.
> > >
> > > Gary
>