C++ member function

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

C++ member function

chagbinary
how does one register a member function into the lua environment?  like in the
constructor, for example?

- Charlie Goff

Reply | Threaded
Open this post in threaded view
|

Re: C++ member function

Nikos K Gorogiannis
Charlie Goff wrote:
> how does one register a member function into the lua environment?  like in 
> the constructor, for example?

Well, the Lua API allows you to register only C functions, so what you
ask cannot be done directly. You need to provide a (C function) callback
for each member function you want to bind and register that as the
appropriate tag method for your object. 

Lots of ways to do that!: 
- let tolua do it for you 
- write the callbacks by hand
- use templates to produce them for you. (For an example on how to do
the latter, see the non-tolua package at the Addons page)
- use lua-swig (or is it swig-lua?) to do similar things with tolua
(YMMV)

Nikos