lua-users home
lua-l archive

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

Since this has been a subject recently, I thought I would post some
ideas I've been having.  I have recently come across 2 packages that
seem quite thorough for building an automatic C++ binding workflow for
arbitrary C++ code.  Here I'm thinking about something complex like
the Computational Geometry Algorithms Library (

There's a project called Cable SWIG from the ITK library ( ) that generates XML using
gccxml.  Essentially it compiles C++ code and spits out annotated
results for building bindings to scripting languages using SWIG.  I've
played with it for a little bit but haven't been too successful.

I've also recently come across luaBind ( ) which seems fairly
complete.  It uses a lot of the Boost metaprogramming stuff which (for
me) makes the code hard to follow.  Is anyone using this?

Currently I make all of my bindings by hand with lots of copy and
paste action and a template class for userdata.  When binding C++
classes My code takes this form:

Object_Udata : public Object, public Udata<Object_Udata>

The Udata<T> class provides metatable generation, inheritance, type
checking and all metamethods.  It is constructed so that the userdata
can be deleted from both Lua and the application on the C++ side which
has no idea about Lua.  This is probably the biggest reason I don't
use toLua++, luaBind, or similar tools.  The other big reason is that
I want to keep the userdata as close to the class as possible by
reducing indirection as much as I can and reducing the cost of type
checking.  I currently do type checking with a unique static pointer
for each Udata class.  All classes have something like

static std::string Object_Udata::name;

I use the address of this string as a type checking mechanism as well
as the name of the metatable in Lua.

I'm wondering if anyone knows of auto-binding  tools that allow for
easy customization of the bindings such as how the metatable is
constructed, whether it allows for __call constructors from Lua,
inheritance, fast type checking, deletion from C++ or Lua, etc.