lua-users home
lua-l archive

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


On Thu, Sep 07, 2006 at 07:36:59PM -0600, mark gossage  wrote:
> Hello Mike,
> 
> I am the current maintainer of the Lua-SWIG bindings.
> SWIG will happily wrapper C++, classes and allow Lua create, call & delete them.
> The support for callbacks & such is limited, but with a little work you can get it going.
> There is no support for writing a subclass of a C++ class using Lua code. Though some languages in SWIG can do this Lua is cannot.
> Other wrappering tools (to my knowledge) are tolua++ & luabind, but I don't know if they can do this.
> 
> If anyone can think of how to do it using normal C++ code, I would be interested to see it, so that I can look at adding this into the SWIG bindings.

Here's an example of how to do this with tolua++ (I assume that by 
'subclass' you mean inheriting from a c++ class and implementing its 
virtual methods). You might find the output code useful:

http://lua-users.org/wiki/ImplementingVirtualMethodsWithToluapp

it requires you to have a way to attach values to your 'c++ object' 
inside lua (on 5.1 we use environment tables on userdatas.. on 5.0 it's a 
bit more complicated), which is done in the example with 'tolua.setpeer'.
You'll probably also need to set a bunch of rules regarding pure virtual 
methods, constructors, etc, but if other swig modules implement it, you 
can probably follow their lead..

Contact me if you need any help..

Ariel.

> 
> Regards,
> Mark
> 
> > I asked a question about the best tool for generating a Lua interface to a lot
> > of C++ classes, and how to subclass in Lua a C++ base class with a Lua
> > interface, but received no response. 
> > 
> > Perhaps I posted my question at an inopportune time, as the Lua conference was
> > ending, so I repeat it.
> > 
> > Thanks for any information,
> > Mike
> > 
> 
>