From: Otared Kavian <otared@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Extracting a column from an array in lua
Date: Fri, 20 Sep 2019 23:00:42 +0200 [thread overview]
Message-ID: <BF60A83C-85C5-4ED0-B0E8-698324AD81A7@gmail.com> (raw)
Hi,
Probably this is a silly question…
In lua, I have an array named t which is determined in a piece of lua code, having (say) two columns and I want to extract for example the first column of t and call the new array tt.
In Matlab, Scilab and friends, this can done by saying tt = t[:,1].
Is this possible in lua?
For the moment I have something like this, but I think it is not a good approach:
\starttext
\startluacode
t = {} -- a silly example of a matrix...
for i = 1, 3 do
t[i] = {}
t[i]["columnOne"] = 10*i + 1
t[i]["columnTwo"] = 10*i + 2
end
tt = {}
for i = 1,3 do -- is it possible to avoid this ?
tt[i] = t[i]["columnOne"]
end
\stopluacode
The first column of the array \type{t} is:
\ctxlua{context.print(tt," ; ")}
\stoptext
Many thanks for any help,
Best regards: OK
___________________________________________________________________________________
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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
reply other threads:[~2019-09-20 21:00 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=BF60A83C-85C5-4ED0-B0E8-698324AD81A7@gmail.com \
--to=otared@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).