Thank you, but this is not what I’m looking for. I know how to sort a table, and I know the Lua table tutorial (the Lua wiki is, IMHO, really terrible and disorganized). I have to construct deeply nested tables and sometimes lose track of what is at what level of my table, so I was wondering if there was an easy way of visualizing a nested table. On the web, you can find a number of (mostly abandoned) projects; the one at http://siffiejoe.github.io/lua-microscope/ says: "Many Lua programmers have written their own pretty-printer or data dumper and some even use it for (de-)serializing Lua data structures.” So I was wondering if any of the Lua users here on the list has something they want to share. Thomas
On 30 Jul 2016, at 16:31, Wolfgang Schuster
wrote: If the requirement is to iterate on a table having the keys, values sorted by key (assuming the keys can be sorted), there are ways to do this. Please see http://lua-users.org/wiki/SortedIteration for an example (this just replaces pairs(t) with orderedPairs(t)).
\starttext
\startluacode
local testtable = { z = "A", y = "B", x = "C" }
for i, j in next, testtable do context("%s:%s",i,j) context.par() end
context.blank()
for i, j in table.sortedhash(testtable) do context("%s:%s",i,j) context.par() end
\stopluacode
\stoptext