3 ms·
> I really wish LuaJIT was the standard for Lua. Lua with a C FFI makes it so much easier to work with C libraries like SDL, as opposed to writing Lua bindings
by naniwaduni 4y ago
> I really wish LuaJIT was the standard for Lua. Lua with a C FFI makes it so much easier to work with C libraries like SDL, as opposed to writing Lua bindings from within C. Lua alone is great, but being able to write C structs in Lua and overload operators is chef's kiss. Of course you can ignore this opinion if you're one of those people who believe C is an abomination to God whose blight should be stricken from the world. To each their own, but for me, Lua is the best C framework out there.
Honestly, I keep finding LuaJIT's FFI to be profoundly disappointing. It falls into the common FFI trap of support, essentially, a C ABI—sure, it parses C declarations, but without preprocessor support and no good way to ask for, say, "just get me all the declarations from errno.h", it cannot work with the universe of code that expects you to pass in e.g. symbolic constants provided in a C header, or preallocated structs, or via preprocessor macros, that maintains compatibility only at the C source level.
It's not an easy problem, to be sure, short of doing the C++ thing and embedding most of C outright.
- krapp 4y agoYes, it's not perfect, but I think it's better than Lua on its own (assuming you don't need anything newer than 5.1)
- phs2501 4y agoYep, pretty much. I wound up writing a thing for this years ago that worked pretty well for the use cases I had at the time, but it was pretty complicated (implementation wise) and had some potential conflicts with other FFI-written stuff that imported "almost but not quite correct" stdlib definitions - since my thing would always import the exact definitions from the system header files. Still, it was fun and I thought it worked reasonably well for what it was. https://github.com/bdowning/lj-cdefdb https://github.com/bdowning/lj-cdefdb