a={b={c=1}}
q=a.b.c
q=2 -- a.b.c = 1
q=a.b
q.c=2 -- a.b.c = 2
Just to confirm, is the behavior above correct?
That is, if I want to modify the contents of an original table through an “alias” variable, is this not possible if I reference its last level?
kalabgs
(FartFella)
March 20, 2023, 6:21pm
#2
Yes that’s how it works. (Number Number one)
1 Like
gertkeno
(Gert)
March 20, 2023, 6:29pm
#3
base types are copied, these are number
, string
, and boolean
. All other types are referenced.
when you write a.b.c
that gets the value 1
which is typeof(1) == "number"
so it is copied to q, and alterations to the copy do not affect the original
when you write a.b
that value is {c}
which is typeof({c}) == "table"
so it creates a reference and alterations to it’s properties are carried over.
2 Likes
system
(system)
Closed
April 3, 2023, 6:30pm
#4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.