* about table operation in lua-ConTeXt
[not found] <mailman.128.1486929767.14600.ntg-context@ntg.nl>
@ 2017-02-13 5:50 ` Jeong Dal
2017-02-13 8:54 ` Henri Menke
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jeong Dal @ 2017-02-13 5:50 UTC (permalink / raw)
To: ntg-context
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 = {}
tempM = m
table.remove(tempM)
context(#tempM, “, ” , #m)
\stopluacode
\stopbuffer
\starttext
getbuffer[test]
\stoptext
___________________________________________________________________________________
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] 5+ messages in thread
* Re: about table operation in lua-ConTeXt
2017-02-13 5:50 ` about table operation in lua-ConTeXt Jeong Dal
@ 2017-02-13 8:54 ` Henri Menke
2017-02-13 8:56 ` Hans Hagen
2017-02-13 9:22 ` Procházka Lukáš Ing.
2 siblings, 0 replies; 5+ messages in thread
From: Henri Menke @ 2017-02-13 8:54 UTC (permalink / raw)
To: mailing list for ConTeXt users
On 02/13/2017 06:50 AM, Jeong Dal 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 = {}
>
> tempM = m
Do a deep copy
tempM = table.copy(m)
> table.remove(tempM)
> context(#tempM, “, ” , #m)
> \stopluacode
> \stopbuffer
>
> \starttext
> getbuffer[test]
> \stoptext
>
>
>
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
>
___________________________________________________________________________________
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] 5+ messages in thread
* Re: about table operation in lua-ConTeXt
2017-02-13 5:50 ` about table operation in lua-ConTeXt Jeong Dal
2017-02-13 8:54 ` Henri Menke
@ 2017-02-13 8:56 ` Hans Hagen
2017-02-13 9:22 ` Procházka Lukáš Ing.
2 siblings, 0 replies; 5+ messages in thread
From: Hans Hagen @ 2017-02-13 8:56 UTC (permalink / raw)
To: mailing list for ConTeXt users
On 2/13/2017 6:50 AM, Jeong Dal 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.
\startbuffer[test]
\startluacode
local t1 = {{0, 2, 4},{2, 3 , 4}, {2, 2, -6}}
local t2 = t1 -- t2 points to t1
local t3 = table.copy(t1)
table.remove(t3)
context.tocontext(t1)
context.tocontext(t2)
context.tocontext(t3)
\stopluacode
\stopbuffer
\starttext
\getbuffer[test]
\stoptext
> Thank you.
> Best regards,
>
> Dalyoung
>
> \startbuffer[test]
> \startluacode
> m = {{0, 2, 4},{2, 3 , 4}, {2, 2, -6}}
> local tempM = {}
>
> tempM = m
> table.remove(tempM)
> context(#tempM, “, ” , #m)
> \stopluacode
> \stopbuffer
>
> \starttext
> getbuffer[test]
> \stoptext
>
>
>
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
>
--
-----------------------------------------------------------------
Hans Hagen | PRAGMA ADE
Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
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] 5+ messages in thread
* Re: about table operation in lua-ConTeXt
2017-02-13 5:50 ` about table operation in lua-ConTeXt Jeong Dal
2017-02-13 8:54 ` Henri Menke
2017-02-13 8:56 ` Hans Hagen
@ 2017-02-13 9:22 ` Procházka Lukáš Ing.
2 siblings, 0 replies; 5+ messages in thread
From: Procházka Lukáš Ing. @ 2017-02-13 9:22 UTC (permalink / raw)
To: mailing list for ConTeXt users
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 <haksan@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:LPr@pontex.cz
Pontex s. r. o. | mailto:pontex@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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: about table operation in lua-ConTeXt
[not found] <mailman.1.1486983601.29608.ntg-context@ntg.nl>
@ 2017-02-13 14:03 ` Jeong Dal
0 siblings, 0 replies; 5+ messages in thread
From: Jeong Dal @ 2017-02-13 14:03 UTC (permalink / raw)
To: ntg-context
Dear Henri, Hans, Procházka,
Thank you for the answers.
It is what I want, and I can complete my code.
Thanks again.
Best regards,
Dalyoung
___________________________________________________________________________________
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] 5+ messages in thread
end of thread, other threads:[~2017-02-13 14:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <mailman.128.1486929767.14600.ntg-context@ntg.nl>
2017-02-13 5:50 ` about table operation in lua-ConTeXt Jeong Dal
2017-02-13 8:54 ` Henri Menke
2017-02-13 8:56 ` Hans Hagen
2017-02-13 9:22 ` Procházka Lukáš Ing.
[not found] <mailman.1.1486983601.29608.ntg-context@ntg.nl>
2017-02-13 14:03 ` Jeong Dal
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).