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 <schuster.wolfg...@gmail.com> 
> 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
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to