ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Extracting a column from an array in lua
@ 2019-09-20 21:00 Otared Kavian
  0 siblings, 0 replies; only message in thread
From: Otared Kavian @ 2019-09-20 21:00 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-09-20 21:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-20 21:00 Extracting a column from an array in lua Otared Kavian

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).