[Kde-bindings] Qt bindings for Lua: status update

Mauro Iazzi mauro.iazzi at gmail.com
Sun Jun 22 10:12:07 UTC 2008


Hi all,
  I have changed much in my Qt bindings for Lua since last time I
announced then, so here there is a little status update. For a bunch
of reasons, lqt has been rewritten from scratch, so it is actually a
completely new bindings generator.

As the previous one it is not complete nor bug-free nor well tested.
It is probably less feature-rich than the previous one. The main
improvement, however, is that it no more depends on GCC-XML. This
means that it should be a lot more portable than before.

The bindings are generated in two steps. A C++ parser (based on the
one written by Roberto Raggi for KDevelop) parses any code which
describes the API (a standard C++ header) and produces an XML
description of it. Then a lua script generates the actual C++ code.
This generated code defines wrappers for the functions that need one
and subclasses that redefine virtual functions, so that Lua functions
can be called as virtual members.

Actually, the generator does that for *any* function and class it
finds, where possible (e.g. when those classes or functions are not
private etc..). It can load filters that forbid to bind some of those
functions or classes. However I put some effort in ensuring it only
tries to bind what is actually public. Eventually, one should be able
to feed it with a header and retrieve the binding as-is.

There is the possibility of specifying how some types are manipulated.
For Qt bindings this means that QPoint and QRect are treated as 2 or 4
numbers respectively, and QByteArray is mapped into a normal string
(QString is a userdata instead).

Enums are mapped into the corresponding strings. As another example of
custom type definition, QFlags (template which defines a bitmask of
OR-ed enum values) are mapped into tables of these strings.

A special class is generated, which has one slot defined for each
signal signature found. Whenever these slots are called, they call
callbacks which can be defined from Lua.

All these features make the binding quite usable. The latest snapshot
can be downloaded from
http://repo.or.cz/w/lqt.git
Simple build instructions are included.

Possible future improvements, apart from polishing and documenting the
code, may be generating SWIG or tolua++ interface files, so that the
binding rely on frameworks that are more stable and clean than the
current one.

I hope someone is interested, comments and feedback are obviously welcome.
Cheers,

mauro



More information about the Kde-bindings mailing list