lua-users home
lua-l archive

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


You could go one step further and ditch JSON.

At a glance, it appears to be trivial to patch the python JSON library[1] to output a Lua table.

prefix it with "return", loadstring()() the result and you're done :-)

-- Pierre-Yves

[1] http://svn.python.org/view/python/trunk/Lib/json/

On Thu, May 19, 2011 at 11:53, Justin Cormack <justin@specialbusservice.com> wrote:
On Wed, 2011-05-18 at 23:04 +0100, Reuben Thomas wrote:
> Given the recent interest in binding Lua to C, I thought the
> following, rough and ready as it is, may be of interest.
>
> I'm pleased to announce Squeeze, the friendly alien:
>
> https://github.com/rrthomas/squeeze
>
> squeeze uses the output of ctypesgen-json, which parses C headers into JSON:
>
> https://github.com/rrthomas/ctypesgen-json
>
> (ctypesgen-json is a modified version of ctypesgen, which parses C
> headers into Python.)
>
> So far, I have done minimal testing: ctypesgen-json successfully
> generates JSON for my system's stdlib.h, which squeeze can load.
> Having done this, I can run drand48(). This is about as early as
> releasing gets!
>
> My own use-case for this is generating C bindings for the Lua version
> of GNU Zile:
>
> http://git.savannah.gnu.org/cgit/zile.git/log/?h=lua
>
> Currently, Zile uses luaposix, lrexlib and lcurses, all of which I
> maintain or co-maintain. Maintaining the C is a drag, and, much worse,
> needing to download and install these libraries is a drag for users
> who want to build Zile. I want to replace all of them with alien. I am
> not sure yet how much mileage there is in this idea, but I intend to
> find out now that I have squeeze.
>

Would be very interested how you get along! It gives some errors on my
stdlib.h (long long and long double support), and also has issues with
sys/socket.h (actually looks like a bug, seems to be confused about
__ss_aligntype which it has actually picked up). I dont know how much
Zile actually needs, if it just needs the nicer bits you are probably
ok. I am currently having to rewrite macros in Lua for my (currently
Linux/glibc only) LuaJIT ffi syscall API
https://github.com/justincormack/ljsyscall but I would like to use some
mix of manual and automatic coding to make it more portable, just trying
the manual route first to see how much work there is, and give myself a
renewed hatred for the CMESG_ macros, which have runtime conditionals...

Justin