lua-users home
lua-l archive

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


On Jun 18, 2014, at 7:37 AM, Andrew Starks <andrew.starks@trms.com> wrote:

> We have our nanomsg binding that we recently remade. It was very C heavy and now it's the opposite. We're making an "nml.core" that looks *pretty much* exactly like the C API. The higher level binding wraps it in a Lua-esque API. 
> 
> If you have made bindings this way, how far do you take the idea of sticking to the C API in your core layer? 
> 
> Do you strive for perfect adherence to the original C documentation? Do you change things like "-1" or "0" to "false", where appropriate? Do you use multiple returns where their API is using pointers?
> 
> -Andrew

We tend to put in a layer to make the Lua interface as “lua-ish” as we can. So indices are 1-based where that makes sense, typed are more Lua-like (so times come back as seconds and fractions of seconds for example), and constants use strings rather than magic numeric values. In addition, for critical interfaces we may even try to simply the API surface area, making the C layer do the heavy lifting to simplify the API.

We have found this helps as some of our Lua developers are not familiar with reading the very low-level C interfaces, particularly when they are stateful. It also makes the Lua code easier to read and maintain, and the interface layer provides some level of abstraction should the underlying API evolve over time.

OTOH this requires more work up front and the need for new API documentation for the Lua scripters.

—Tim

OT: I was amused that my spell checker tries to change “scripters” to “scrapers” :)