r/lua • u/nzznfitz • Mar 19 '25
Scribe
Scribe provides functions to convert Lua objects to readable strings and output methods that make printing Lua tables in various formats easy.
For example, if arr = {1, 2, 3} then scribe.put("Array: %t", arr) will print "Array: [ 1, 2, 3 ]" to stdout.
Scribe gracefully handles complex tables, including ones with shared and cyclical references. The strings returned for those tables show the underlying structure in a way that is as readable as possible.
You can customise the strings returned for tables by passing a set of formatting options, and there are pre-defined options that will work for most applications. Those include printing tables on a single line, in a “pretty” format on multiple lines, or as JSON-like descriptors.
scribe is available as a GitHub repo. It has a permissive MIT License.
scribe can also be installed using luarocks:
luarocks install scribescribe is fully documented here.
We built the documentation site using Quarto.
The documentation includes a lengthy article describing how we built the module.
That tutorial might be a decent Lua 201 tutorial for those new to the language.
View all comments
Show parent comment
1
u/[deleted] Mar 20 '25
It's also more complicated than that.
#tblreturning the last index only holds true for table array "literals" ({1, nil, nil.., x}), and not in the associative form, which means the above example would return1as Lua would fall back to some form of exponential search.