lua-users home
lua-l archive

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


2013/3/11 Gabriel Duarte <confusosk8@gmail.com>:

> I'm writing a graphical toolkit (https://github.com/gabrield/stk) and
> now, I would like to bind it to Lua. I looked for some automatic bind
> generator, that could read my .h 's and expose the API to Lua. I have
> alreary looked at http://lua-users.org/wiki/BindingCodeToLua but could
> not get much of it. Tips?

You'll get advice from people who like `swig` etc, but please do not
take it.  Rather, consider the following opinion of David Heiko Kolf
from another recent thread.

> - Even more subjective and hard to define, but a module should show some
> "Lua-style".  Sometimes I see a module and it looks to me like raw C
> bindings and I keep thinking that the API might be a lot simpler in Lua.

For example, I see from your .h files that you have dozens of tiny
functions which of necessity have arguments that map easily to C.
In some cases, the parameters are typed but not named. That is not
going to be turned into pretty Lua-style bindings by swig etc.

A Lua-style interface might have only a few functions but exploit the
possibility of table arguments. The great thing about those is that
the key values themselves make the user program self-documenting.
Your call sequence could be something like

   widget:set{x=10,y=20,height=100,width=200,color=rgb(0,255,180)}

instead of four or five calls to little functions.

The only excuse for raw C bindings is that the original package is
huge but very well documented, like Qt for example, so that you then
do not need to write new documentation. Neither of those properties
apply to your project at this stage.