lua-users home
lua-l archive

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


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