From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/95611 Path: news.gmane.org!.POSTED!not-for-mail From: Wolfgang Schuster Newsgroups: gmane.comp.tex.context Subject: Re: lua tables - how do you cope? Date: Sat, 30 Jul 2016 16:31:22 +0200 Message-ID: <579CBA3A.6070308@gmail.com> References: <8733E1CA-0DFE-4B10-BC34-9CEC8BB246AB@uni-bonn.de> <579ca5be.031dc20a.f2c35.463e@mx.google.com> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1916580009867362848==" X-Trace: blaine.gmane.org 1469889138 22864 80.91.229.8 (30 Jul 2016 14:32:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 30 Jul 2016 14:32:18 +0000 (UTC) User-Agent: Postbox 4.0.8 (Macintosh/20151105) Cc: "Schmitz Thomas A." To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Sat Jul 30 16:32:00 2016 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTVJ1-0005qH-2W for gctc-ntg-context-518@m.gmane.org; Sat, 30 Jul 2016 16:31:59 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id F3E1513A1F; Sat, 30 Jul 2016 16:31:39 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Lr0dFtgkXPpq; Sat, 30 Jul 2016 16:31:39 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [IPv6:::1]) by zapf.ntg.nl (Postfix) with ESMTP id 490AA13A7C; Sat, 30 Jul 2016 16:31:39 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 2656C13A20 for ; Sat, 30 Jul 2016 16:31:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qRp8B-y4e1Hu for ; Sat, 30 Jul 2016 16:31:36 +0200 (CEST) Original-Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 8995513A1F for ; Sat, 30 Jul 2016 16:31:26 +0200 (CEST) Original-Received: by mail-wm0-f43.google.com with SMTP id o80so187121602wme.1 for ; Sat, 30 Jul 2016 07:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to; bh=spgA968L9P+kbLsdkNhZC+7sO9IuPOOX7MnRnHCxNsc=; b=N8H0FBTfzKvtSliINg0UyplVXZ+b0mpc/2GIJH+aLb7HQpRIE5Z7Mtr4rUB96u/8A5 c2OpZ5Zy63zY3BG1GhY1fg88HBZjk0HQEj1ibS0Q8tkfVp6UbbjXI+G/LLRjU6fkp3dL 64Hw6m//2b8Iq4PCVlCfMriLVlev2dap4rTV2F2SwhmeusXcqVqqog6498WxchJIcCvS bZ7DTjppYCp+xhbvnsGPmmJCtGkIvES+8cZi4IY3UvTevheUFdBBawB6gzO4PUDy8GDJ trRPla+Y+jVnrNeShsGzo6ZheNU5it5fyxPx+12obtVNCzdvvpsE09Zjz2ly2jeDLpS0 114g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to; bh=spgA968L9P+kbLsdkNhZC+7sO9IuPOOX7MnRnHCxNsc=; b=SZoYLKmu6tnFf5V9RE8H6Q53CU4UshnP3Fee6AqiTFEciDH3qcPm+8/tJrfzTyw/Vs XQcvKsJ27X0u557k9jELQSMJc85eBDUN3NETHs/ypxyTEfhKt47tnJQIOTFnJXxPaLNU zgDOfLywVWcVMm6lGMOpg0252MMEE183Tti21PIuELJrzrdw1FW4KDHUYF9mUHpbLW1U EYZKLYDtpLJKy9HdNKPCzbDozBqwZWAylkai6v/S2oPD22+fi7PLk7gTJY+LCHahcXam B+oXJJ0QX2c/tHZ7JVD+grlvsfQ7l0ZoucPIUz+EtFj28eT1Fzj7Rek3b5VNdZ8pQUNF efIA== X-Gm-Message-State: AEkoousa2jnqwuRvEEzF6pr6OI3xge2+lEy1Hp//4Hjt7L0ROqx8i5KRL52JW+/xp5Ngrg== X-Received: by 10.194.32.195 with SMTP id l3mr42776305wji.27.1469889085900; Sat, 30 Jul 2016 07:31:25 -0700 (PDT) Original-Received: from keima.localdomain (x2f2696f.dyn.telefonica.de. [2.242.105.111]) by smtp.gmail.com with ESMTPSA id va3sm21542268wjb.18.2016.07.30.07.31.24 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 30 Jul 2016 07:31:25 -0700 (PDT) In-Reply-To: <579ca5be.031dc20a.f2c35.463e@mx.google.com> X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.16 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.org gmane.comp.tex.context:95611 Archived-At: This is a multi-part message in MIME format. --===============1916580009867362848== Content-Type: multipart/alternative; boundary="------------040504040607070102020906" This is a multi-part message in MIME format. --------------040504040607070102020906 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit > 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 --------------040504040607070102020906 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
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
--------------040504040607070102020906-- --===============1916580009867362848== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly90ZXguYWFuaGV0Lm5ldAphcmNoaXZlICA6IGh0dHA6Ly9mb3VuZHJ5LnN1cGVsZWMu ZnIvcHJvamVjdHMvY29udGV4dHJldi8Kd2lraSAgICAgOiBodHRwOi8vY29udGV4dGdhcmRlbi5u ZXQKX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX18= --===============1916580009867362848==--