lua-users home
lua-l archive

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


What are the automatic generators compatible with Lua 5.2 (rcX) ?
 -dub?
 -toLua++?
 -SWIG?

Thanks.

Vinicius Jarina.
 

On Wed, Dec 7, 2011 at 6:05 AM, Gaspard Bucher <gaspard@teti.ch> wrote:
On Mon, Dec 5, 2011 at 12:32 PM, steve donovan <steve.j.donovan@gmail.com> wrote:
On Mon, Dec 5, 2011 at 1:25 PM, Daniel Silverstone
<dsilvers@digital-scurf.org> wrote:
> Then again, I don't try and bind C++ and I don't try and bind dynamically
> changing APIs.

That's the rub. I pity the poor bastards who have to bind to C++.

Other than the API, nothing is "official" in the Lua world ;)

steve d.


A very powerful and very badly documented tool is "dub": it uses Doxygen to parse the C++ headers and creates the bindings accordingly. This thing handles:

- objects deleted by Lua
- objects deleted in C++
- objects only owned by C++ (Lua destructor does nothing)
- exception safe
- binding inheritance (you write some custom bindings that you use on different C++ classes not necessarily with a same base).
- hand made (more Luaish) bindings

The last point lets you insert custom code that will be used instead of the method call. You still have automated type checking and exception protection but you can use things like multiple return values or simply create bindings for methods that do not exist in the C++ class:

For example, these are two methods for the QWidget binding:

This one returns two values:

  globalPosition: |
    QPoint pt = self->mapToGlobal(QPoint(0, 0));
    lua_pushnumber(L, pt.x());
    lua_pushnumber(L, pt.y());
    return 2;

This is a method that does not exist in Qt:

  globalMove: |
    self->move(
      self->mapToParent(
        self->mapFromGlobal(QPoint(x, y))
      )
    );              

The documentation is ... poor, but I answer emails. And this tool works: it is used everywhere in lubyk (http://lubyk.org).


Cheers !

                                                               Gaspard