lua for data representation - citrons.xyz
“here is a function that for any string, creates the correct multiline string to represent it:”
Jump to Highlight ↗
my major advocacy is that lua is a very good general purpose language. this is not an opinion shared by all. lua’s major design goal was extending and embedding into existing programs. I think the simplicity and flexibility in design persued towards the end of that goal extends to make lua a very good language in general. that said, it does its job quite well as an embedding language, and one of its more interesting use cases (and actually, one of its oldest use cases) is as a data or configuration format.
lua’s syntax provides many niceties. for instance, lua has an infinite family of multiline strings: the most basic one starts with [[ and ends with ]]. however, any amount of equal signs can be put between the two square brackets: print([======[hello, world]======]). the only way to close a [===[ is with an accompanying ]===], not with a ]] or a ]==], or a ]====].
local function stringize(str) local equal_signs = "" for e in str:gmatch("](=*)]") do if #e >= #equal_signs then equal_signs = e .. "=" end end return ("[%s[%s]%s]"):format(equal_signs, str, equal_signs) end of course, you can just use string.format with %q, but multiline strings usually provide nicer looking and more compact results. these strings are very good for representing lua code as strings in other lua code.
anyway, download this file. if you want to consume massive amounts of memory and possibly crash your computer, run it in cpython. if you want to see “hello, world” printed 5 million times, run it in lua. lua’s parser is designed to handle massive files with stride, which is fairly unique and quite necessary if lua is to be used for this purpose.
📝 Your Private Notes & Highlights 🔒 Only visible to you
Log in or create a free account to keep private highlights and personal notes on your stored picks.
Featured on Storesso
Are you the creator of citrons.xyz? Share your verified feature badge on your website, or export a custom 4:5 editorial social card for Instagram and X.
Generate a 1080×1350 vertical high-res feature card tailored for social sharing.
Instagram & X Feature Card
Export a polished, high-resolution 4:5 editorial graphic displaying your verified inclusion in the Storesso Discovery Index. Perfect for launch threads, founder updates, and newsletters.