4 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 fr
by krapp 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.
Lua is also my go to suggestion whenever threads about which language to use for configuration come up. The syntax of lua tables are basically JSON, except without quoting keys and with comments. And the overhead of embedding it is likely close to nil compared to the interpreter for YAML or whatever.
It's a nice language. Wish I had something more profound and complex to say about it. I would just suggest considering JuaJIT if you ever do need to work with C and it's allowed. Or just Lua if you're a masochist and want to deal with the stack.
- 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
- rleigh 4y agoHave you tried hooking up the C functionality with "sol2" and regular Lua? I have been prototyping with it the past couple of weeks, and it took just an hour to wrap all of the glm matrix and vector types, including overloaded operators to do fully transparent vector and matrix algebra in Lua, including passing of values to and from the outside world. I was really impressed by how straightforward and simple it was.
- krapp 4y agoI wasn't aware of it but I'll check it out.