Parseback: A pure-Lua introspection library for LuaJIT's FFI ctype objects

49 points by todsacerdoti on 2024-05-15 | 11 comments

Automated Summary

Parseback is a pure-Lua library that provides introspection capabilities for LuaJIT's FFI ctype objects. It takes information from ffi.typeinfo() to create useful descriptions of ctype objects as Lua tables, C declarations, and GraphViz diagrams. The library is a single Lua file that can be installed in the $LUA_PATH. Parseback is MIT licensed. The main functions provided by parseback include typeinfo(ct), which returns a table tree describing the given type, and asdot(ct [, horizgroups]), which creates a diagram of the whole type structure in the 'dot' language. The library is designed to help developers understand and work with ctype objects in LuaJIT's FFI.


sillysaurusx on 2024-05-15

I’ve often felt great LuaJIT’s "just paste C declarations for FFI" was its greatest achievement. I tried to dig into the source code and port the C parser to Python, but it was beyond me at the time.

Still seems like a good idea that I hope someone will do.

mcepl on 2024-05-15
sillysaurusx on 2024-05-15


imtringued on 2024-05-15

How do you resolve the declarations for your particular system? Do you run the preprocessor?

lowq on 2024-05-16

It doesn't run the preprocessor, so you have to expose constants as externs, for example. Things like `int32_t` still work, so it must just have built in support for standard types.

andrewmcwatters on 2024-05-15

It's by far the best FFI implementation in the industry across all languages. You can even setup a GCC workflow to automate the bindings by stripping information from headers.

I'm disappointed by the FFI experience everywhere else, it makes you feel like you're doing software development in the stone ages.

lowq on 2024-05-16

It's fantastic when embedding Lua in a self contained executable too! I have a routine that goes through and 'cdef's certain headers that were also #included at compile time. Super powerful extending a C program this way.

lifthrasiir on 2024-05-16

I think that's because FFI is only a small (and rather easily automatable in other means) portion of making a usable binding for the target language.

vitiral on 2024-05-15

Does anyone know if there's a Lua (not LuaJIT) library for the ffi functionality? I wonder if this library could work for both

chadcmulligan on 2024-05-16

There's this, I haven't used it but seems to be used a bit

Edit and Alien -, they both use libffi -

sneusse on 2024-05-15