Lua for data representation (2025) (opens external site)
View full thread · View on Hacker News
To get push notifications on iPhone or iPad, add Hack and Chat to your Home Screen: tap Share → Add to Home Screen, then open the installed app and enable push in Settings.
View full thread · View on Hacker News
Let’s see, no native json support. This day and age it should be built in. No array support: is {} an empty json object or empty json array? Just add the dang arrays already.
LuaJIT is very awesome! Amazingly fast. Does it support the latest Lua? Nope it doesn’t. Lua is at 5.5 or something, LuaJIT at 5.2 maybe.
Default global vars? Nope. More awkward than cute. Maybe introduce some profile / pragma to invert that. Everything should be local by default not global.
Speaking of Roblox, they liked Lua so much they forked it and created a new language altogether! Luau which is only fully compatible with 5.1
I mean it’s still a nice language for a configuration format but otherwise I think that summarizes why people might not be reaching for it as much, in other cases.
Replies (4)
https://luarocks.org/modules/luarocks/json4lua - https://luarocks.org/modules/winterstream/wjson - https://luarocks.org/modules/xpol/rapidjson - etc.
Lua supports arrays; it has optimizations when all of a table’s keys are integers. Keep in mind that AWK is the same way: There’s no numeric array in AWK per se either, just AWK’s version of a “table”, but it works just fine when all of the keys are integers.
Keep in mind that I have a fork of Lua which is 116,224 bytes in size (security hardened Lua 5.1 with `lfs` support); Lua is tiny and that’s why it does not have a built in JSON library nor will it wash the dishes for you.
Versions of Lua after Lua 5.1 introduced changes which broke backward compatibility. Lua 5.1 is smaller than newer versions of Lua, runs great, and is incredibly fast. I see Lua 5.5 as a different language than Lua 5.1, even though one can make a polyglot program which can run in both. Lua 5.1 is also the point from which a bunch of offshoots were made: luau (Roblox Lua), LuaJIT, etc.
Replies (1)
I guess my point is that why it's not picked as large of a support. I can see that being a good reason for Lua in 2006 when JSON was still not as popular but for better or worser, it's taken over so having built in JSON support would help, especially for a language geared for configuration and data representation.
> Keep in mind that I have a fork of Lua which is 116,224 bytes in size (security hardened Lua 5.1 with `lfs` support); Lua is tiny and that’s why it does not have a built in JSON library nor will it wash the dishes for you.
Agree, that's where it really shines, it's small and embeddable.
> Lua 5.1 is also the point from which a bunch of offshoots were made: luau (Roblox Lua), LuaJIT, etc.
But you see how the official site doesn't seem to issue bug fixes for anything lower than 5.4 yet everyone says 5.1 is the version to stick with. And there is luau and LuaJIT as well, that I think explains a bit why people are embracing it as eagerly any longer.
Replies (1)
https://pluto-lang.org/
The reason I like Lua is because I use it like a tiny Perl, but, unlike Perl, I already include the entire language with my open source project (it’s embedded in another program I wrote) so my Lua scripts in said project will run on any POSIX compliant system: The Lua fork I use and include also compiles as a standalone scripting language.
Lua has many quirks (global by default etc.) but with a language server like https://luals.github.io/, you can detect most of them easily plus optional type annotations.
Replies (1)
Replies (1)
Replies (1)
I would love to see a POSIX standard for Lua (probably based on Lua 5.1); it’s widely enough deployed that a standard for it would make sense. Right now the standard is either PUC Lua 5.1 or whatever the latest release of PUA Lua is at a given time.
I prefer Lua over Perl/Python/Ruby because I know I can get a Lua runtime going in whatever environment I’m in—e.g. when writing my Lua book, I used my personal fork of Lua 5.1, but the person I was writing the book with was using Moonsharp (Lua in C#) since they were a C# developer. We could easily share code with each other.
Replies (1)
Continue this thread (1 replies) →
All the Lua 5.x versions that I have seen have small compatibility issues, and that's why many projects stick with what it's compatible with 5.1 only.
C++ doesn't have any "native json support" either, and that's fine. I don't think JSON is that critical. You can use a library for the kind of serialization that you want. Neovim uses JSON and Lua extensively, and it just uses a C library inside.
It's true that `{}` doubles down as an empty array or an empty map. It is not a problem that often, IME. You also can't signal that a certain key in a map is `nil`, but you can use a sentinel for it. You can do the same to disambiguate between these two.
Different features hit differently to different people. I agree that global by default seems so wrong, but I just go used to it, and I don't care anymore. To me, the main deal is not that Lua doesn't have this features by default, is more that, when I want them, there is no generally agreed library/framework that can plug all the features in a unified, coherent way. Penlight should be that, but I don't like it that much.
This is something that personally hits me the most, because I'm used to Qt. With Qt, I have tons and tons of functionality and a well established community and practices.
Replies (2)
https://pluto-lang.org
But you see how "why isn't Lua more popular" is answered with that? Do I start with 5.5? 5.3 and below seems is EoL already per the official site, they only have 5.4 bug fixes. It's a bit like C++ I guess, use only a small subset of features perhaps?
> C++ doesn't have any "native json support" either, and that's fine.
Unlike C++ Lua posits itself as an easy data representation and configuration language but it doesn't have a built-in way to load one of the most popular serialization formats out there these day.
> Different features hit differently to different people.
Definitely, I am just explaining why it doesn't appeal to me and the reason I heard other people didn't start or continue using it.
Replies (1)
If it had a few changes and perhaps some optional additions (while keeping a "classic" or "standalone" version), it would probably be more popular.
> Unlike C++ Lua posits itself as an easy data representation and configuration language but it doesn't have a built-in way to load one of the most popular serialization formats out there these day.
But that's the thing: if you want to represent data or configure something, wouldn't you prefer to do it in Lua? Seems the history of the language was using Lua syntax for the data representation, which is a bit more convenient than JSON for a few schemas. JSON is useful for interoperability, but it's far from my favorite for making a configuration file. The next project I'm working on is a small Lua script that will let the user configure itself via Lua, because that's more convenient than a static config format.