Hello,

tables in Lua are "shared" - there is one copy until you "deep copy" one to 
another.

Se  comments bellow -

On Mon, 13 Feb 2017 06:50:38 +0100, Jeong Dal <hak...@me.com> wrote:

Dear all,

It may be a slight off topic.
In the following example, I copied a table “m” to “tempM”, and remove the last 
row of tempM.
Then the output is “ 2, 2”
I checked the contents of tempM and m and found that they are same even though 
I didn’t touch m.
I want to remove the last row of tempM while keeping the table m untouched.
Please tell me how to do it.

Thank you.
Best regards,

Dalyoung

\startbuffer[test]
\startluacode
 m = {{0, 2, 4},{2, 3 , 4}, {2, 2, -6}}
local tempM = {} -- OK, 'tempM' and 'm' are different tables - try 
'print(tempM, m)' - you'll get two addresses

tempM = m -- Now, 'tempM' and 'm' will point to the same table - "the 'm' table"
-- The original 'tempM' table will be forgotten and removed during next garbage 
collection as there is no other reference to it
-- ('tempM' starts pointing to 'm', too)
table.remove(tempM) -- Will remove from one
context(#tempM, “, ” , #m) -- Obviously - both table point to the same object, 
try again 'print(tempM, m)'
\stopluacode
\stopbuffer

\starttext
getbuffer[test]
\stoptext

Best regards,

Lukas


--
Ing. Lukáš Procházka | mailto:l...@pontex.cz
Pontex s. r. o.      | mailto:pon...@pontex.cz | http://www.pontex.cz | 
IDDS:nrpt3sn
Bezová 1658
147 14 Praha 4

Tel: +420 241 096 751 (+420 720 951 172)
Fax: +420 244 461 038

___________________________________________________________________________________
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 via email to