lua-users home
lua-l archive

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

On Thu, Jun 19, 2014 at 5:49 PM, Andrew Starks <> wrote:
I share your opinion. When I took a stab at writing a nanomsg binding, I paid no mind to the original library. This made for a lot of very complicated C code that I don't ever want to touch again, for as long as I shall live. 

Rule #1: Get thee from C to Lua as fast as possible.

This means that your binding will look very much like C. Where it doesn't, it will most likely be due to memory management, and data types. The other differences are "true" and "false" and multiple returns. Here, Lua can make it less tedious and the amount of variance is probably a judgement call. 

From there, you can, and according to your taste should, "do it all again" by wrapping the core binding around an object model. 

This is the process that we are employing, right now. "nanomsg" is very well done, for this purpose, but I can't imagine a binding for which I would not try this approach first.

I read this post and wanted to see if I could write up a binding for nanomsg. I worked from the nanomsg manpages, taking each exported function and writing up a binding. The results are found in the two files here:

I haven't used nanomsg previously, but the binding seemed mostly straight-forward. It took a couple hours to write the initial code from the docs, then another couple hours to implement this tutorial and work out the bugs:

Compare with the version written in Lua:

There's almost certainly a bit more work that would need to be done, as well as further thought for how data should be handled once it leaves nanomsg's C API, but I think someone familiar with both Lua and nanomsg would be able to take it from there (which is the benefit of working with a binding that stays close to C). At any rate, I'll keep and maintain it in Lua-cxx along with the other bindings I have there.

Aaron Faanes <>