lua-users home
lua-l archive

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


On Thu, Mar 14, 2013 at 2:14 PM, Ezequiel Garcia <elezegarcia@gmail.com> wrote:
> was to write an ad-hoc script to parse the header and produce the binding.
> I choose Perl for historical reasons, but you could choose Lua itself,
> of course.

There is another way, which is to write the module in a C-sort of
form, and process it into plain C.

For instance, this is the _source_ of winapi:

https://github.com/stevedonovan/winapi/blob/master/winapi.l.c

Looks just like C, until:

def set_encoding (Int e) {
  set_encoding(e);
  return 0;
}

which gets translated into (see the .c file in same directory) as

static int l_set_encoding(lua_State *L) {
  int e = luaL_checkinteger(L,1);
  #line 56 "winapi.l.c"
  set_encoding(e);
  return 0;
}

plus, l_set_encoding is bound to 'winapi.set_encoding' without any
tedious extra typing.

There's a 'class' construct which really cuts down on the amount of
boilerplate that needs to be typed as well.

This is done using LuaMacro (definitions in lc.lua).  The ironical
thing is that LM was written to preprocess Lua code, but I've mostly
used it to rewrite C ;)

steve d.