lua-users home
lua-l archive

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

On 5 December 2011 13:34, steve donovan <> wrote:
> On Mon, Dec 5, 2011 at 2:01 PM, Michal Kottman <> wrote:
>> Yes, some of us poor bastards even have to create our own binding
>> generators (lqt) just to bind a huge C++ framework (Qt) to Lua :)
> A noble effort, sir, congratulations. Does lqt by its nature do
> general C++, or does it just specialize to the idioms used by Qt?

The lqt generator first parses all the headers into a XML file
describing all the classes, their methods and arguments using an
"underground" C++ parser cpptoxml. Because the Qt framework is
designed rather cleanly (no references to arrays of pointers, lot of
preprocessor magic etc.), there is no preprocessing/cleanup necessary,
cpptoxml can handle the definitions.

The second phase is actually using the data in the XML to generate the
binding. Apart from binding classes/methods, it also features:
* virtual methods - you override methods in objects created from Lua,
even protected methods
* enums - can be passed as arguments as either strings or numbers
* custom fields on objects - they behave as standard Lua tables thanks
to custom userdata environments
* some template instatiation - from a hand-written list, which was
created by inspecting the template instances used in the Qt API
* some operator overloading - for those operators that are relevant to
Lua, others can be renamed to functions, like << is renamed to IN

Qt specifics:
* signal/slot mechanism - you can use Lua functions as slots (loosely
coupled event handlers in Qt)
* memory management - you can choose the way you handle the management of object
** no management - you have to explicitly call obj:delete()
** Qt parent-child mechanism - when the parent is deleted, all child
objects are deleted too, this means you only have to take care of 1
** Lua managed - through __gc metamethod, deleted when garbage-collected

The generation pipeline (done in CMake) is very Qt-bound (especially
how the individual modules are organized and interdependent), however
it should be possible to use the individual pieces to generate a
binding to other C++ software. It highly depends on the
quality/cleanness of the API (I don't know how to call it exactly)
that is to be bound.

The generator is due for a rewrite however, because it is becoming an
unmaintainable mess I'm afraid :(

The positive thing about the whole thing is that using Qt, Lua can
actually be used as a main application programming language, with
access to GUI, networking, multimedia, databases, XML processing, even
WebKit - you can play around with webpages in Lua (great for testing).