lua-users home
lua-l archive

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

On 28 February 2015 at 23:16, Sean Conner <> wrote:
  This isn't about luaposix per se, but this is prompting this observation
about Lua wrappers for C APIs: they tend to mimic it quite literally (to the
point where I think I've said this before: if I wanted to code in C, I know
where to find it).
  When I look over existing Lua modules like luasocket, luaposix, various
other syslog implementations, I tend to see an almost slavish approach to
mimicking the C API as closely as possible, instead of, for lack of a better
term, Luaizing the API.  
  The thing is---am I alone in doing this?  Do I have a different way of
handling C APIs in Lua?  Is it more a matter of "following the C API as
directly as possible because of existing documentation"?  Or of "this is
easier to do to get this out the door"?  Or even "I didn't even think of
doing that"?

  -spc (I'm really puzzled over this, as the modules I wrote tend to work
        radically different from modules (that cover the same C API) that
        others have written ... )

So when I write bindings, I tend to split them into a 'low level' and a 'high level'.
I believe this is pretty common.

The low level library mimics the C library almost identically, and documentation is usually something like "go read the man page".
This low level library I usually write in C; usually you see this as a "" or similar library
The low level needs to be perfect, or you have memory leaks, seg-faults, etc.
Also luckily, once it's done you don't usually need to modify it much: C apis rarely change.

However. the high level library is where all the lua idioms come in:
  - Valid lua iterators
  - Aliases for enums
  - Class systems
  - Wrappers
  - Documentation!
It's written as a wrapper around the low level library.

When time is running out, the high level level is the bit that gets less love,
but it's also where all fun stuff happens.