[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re:Automatic C++ Lua bindings
- From: "Linker Lin" <linker.lin@...>
- Date: Wed, 22 Aug 2007 0:7:17 +0800
Maybe the tolua++ is a good choice~
:)
Try it...
------------------
------------------ Original ------------------
From: "Wesley Smith"<wesley.hoke@gmail.com>;
Date: 2007年8月21日(星期二) 凌晨03:26
To: "Lua list"<lua@bazar2.conectiva.com.br>;
Subject: Automatic C++ Lua bindings
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 ( http://www.cgal.org/
).
There's a project called Cable SWIG from the ITK library (
http://www.itk.org/HTML/CableSwig.html ) 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 (
http://www.rasterbar.com/products/luabind.html ) 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.
wes