[NTG-context] lua tables - how do you cope?

Wolfgang Schuster schuster.wolfgang at gmail.com
Sat Jul 30 16:31:22 CEST 2016


> Joseph Canedo <mailto:josephcanedo at gmail.com>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20160730/c1b649e5/attachment.html>


More information about the ntg-context mailing list