Joseph Canedo
30. Juli 2016 um 15:04

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

Wolfgang