It's not a coincidence that Lua's good at representing data -- the language started life as a data-specification syntax called Simple Object Language. Or SOL (sun), which evolved into Lua (moon). If you've used BibTeX, then SOL will look familiar -- also not a coincidence! (BibTeX was first.)
Lua as a whole is incredibly underrated, especially given things like LuaJIT - I don't understand why it felt out of popularity with most people. Maybe related to Roblox.
I think what happens with Lua is that, when someone decides to use it for a purpose, it ends up embedded and thus the ‘secret sauce’ for the app.
Which is to say, Lua is used practically everywhere.
I recently added Lua bindings to the BlenderUI library, and it was just so easy and fun - and immediately made nice UI development so productive. Coding up a BlenderUI with a Lua REPL is a very rewarding thing to do indeed.. so much so that I added Lua bindings to CUI, also!
The number of forks of Lua is one sign that it's a very practical and useful technology. LuaJIT is essentially a half-compatible fork, and still on its own path to maybe become a full fledged fork.
It doesn't have a good standard library since it was designed to be embedded in C/C++ programs for scripting rather than being a standalone scripting language and the package management ecosystem never fully took off.
I always try to learn some Lua every 6 months or so and just get annoyed. I don’t doubt its usefulness, I just personally can’t bring myself to like it. 1-based indexing, no actual array/list type, depending on the version you might not even have bitwise operators. gotta call into a goddang library to AND 2 numbers together. like what the heck man
Lua is made to be embeddable in a safe and relatively minimal way. That's why it shows up in a lot of places. Want to run 100 independent Lua "VMs" in your process? Not a problem, it's safe to do so by default.
Most developers don’t care about Roblox. Lua is cute but awkward.
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.
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.
luajit and luau supporting 5.1 only is a feature: it freeze language so no more backward compatibility breaks
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.
For better or worse CorsixTH makes extensive use of these techniques, as the config format [1], the translation format [2], and even the format for the update check [3]
In my experience, tying your data format to a programming language is a mistake you most likely will pay for later. For example, when you need access to that data from a different programming language.
using json is an option (which is mentioned in the article). But lua gives you some features that json cannot match - it's powerful, may be too powerful tbh.
I'd say a tool-command format is a distinct and very good syntax for arbitrary data representation. The input consists of lines; each line starts with a command name, followed by optional arguments. There is some continuation syntax to wrap long arguments. The order of lines matters because each line is executed with its argument by some handler; the handler may modify the execution context. Aside from the command name there is no syntax other than whitespace. And since it quietly accumulates the context it gets very compact too.
It's not a coincidence that Lua's good at representing data -- the language started life as a data-specification syntax called Simple Object Language. Or SOL (sun), which evolved into Lua (moon). If you've used BibTeX, then SOL will look familiar -- also not a coincidence! (BibTeX was first.)
The article indirectly nods to that history by linking here: https://www.lua.org/history.html#:~:text=All%20this%20config...
Lua as a whole is incredibly underrated, especially given things like LuaJIT - I don't understand why it felt out of popularity with most people. Maybe related to Roblox.
I think what happens with Lua is that, when someone decides to use it for a purpose, it ends up embedded and thus the ‘secret sauce’ for the app.
Which is to say, Lua is used practically everywhere.
I recently added Lua bindings to the BlenderUI library, and it was just so easy and fun - and immediately made nice UI development so productive. Coding up a BlenderUI with a Lua REPL is a very rewarding thing to do indeed.. so much so that I added Lua bindings to CUI, also!
The number of forks of Lua is one sign that it's a very practical and useful technology. LuaJIT is essentially a half-compatible fork, and still on its own path to maybe become a full fledged fork.
I myself have gone almost all-in on Lua Lapis (running in OpenResty) and Lua Fullmoon (running in RedBean) for anything server related.
It doesn't have a good standard library since it was designed to be embedded in C/C++ programs for scripting rather than being a standalone scripting language and the package management ecosystem never fully took off.
Thats a feature, not a bug.
I always try to learn some Lua every 6 months or so and just get annoyed. I don’t doubt its usefulness, I just personally can’t bring myself to like it. 1-based indexing, no actual array/list type, depending on the version you might not even have bitwise operators. gotta call into a goddang library to AND 2 numbers together. like what the heck man
when i was still involved in wikipedia template and module development, i was quite surprised that it mainly used lua.
Lua is made to be embeddable in a safe and relatively minimal way. That's why it shows up in a lot of places. Want to run 100 independent Lua "VMs" in your process? Not a problem, it's safe to do so by default.
Most developers don’t care about Roblox. Lua is cute but awkward.
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.
Wanting things like native JSON support goes against the Lua spirit. Something like that belongs in a library, and lo and behold, there are several:
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.
luajit and luau supporting 5.1 only is a feature: it freeze language so no more backward compatibility breaks
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.
It hasn't. Luau comes with two runtimes. Lua distros are many.
For better or worse CorsixTH makes extensive use of these techniques, as the config format [1], the translation format [2], and even the format for the update check [3]
[1] https://github.com/CorsixTH/CorsixTH/blob/master/CorsixTH/Lu...
[2] https://github.com/CorsixTH/CorsixTH/blob/master/CorsixTH/Lu...
[3] https://github.com/CorsixTH/CorsixTH/blob/gh-pages/check-for...
In my experience, tying your data format to a programming language is a mistake you most likely will pay for later. For example, when you need access to that data from a different programming language.
I agree, but Lua is the singular language that might just maaaybe be the exception to that sometimes.
If you need to access the data from a different language, you just load Lua in the other language.
While I am even doing that in a project if mine, I'd rather not load Lua and instead just run `serde_json::from_str()` or similar.
using json is an option (which is mentioned in the article). But lua gives you some features that json cannot match - it's powerful, may be too powerful tbh.
Many non-Lua folks don't understand this point: once you've got it in Lua you can put it in anything, anywhere.
Unrelated to the content: the ad at the bottom is from a very delightful ad network https://john.citrons.xyz/.
I'd say a tool-command format is a distinct and very good syntax for arbitrary data representation. The input consists of lines; each line starts with a command name, followed by optional arguments. There is some continuation syntax to wrap long arguments. The order of lines matters because each line is executed with its argument by some handler; the handler may modify the execution context. Aside from the command name there is no syntax other than whitespace. And since it quietly accumulates the context it gets very compact too.
It’s also pretty nice that a verb plus a table is implicitly a function call. This means you can easily do things that seem to be types:
This syntax is inherited from one of Lua's predecessors, Sol, for compatibility, and in Sol, it actually means types!
There are a couple of snippets here that refer to it (search for @track):
https://www.lua.org/history.html