0

My code is:

a = {"a1","a2","a3"}
b = a
b[1] = "b1"
print(a[1])

I can't understand why the result is "b1" instead of "a1".

The same is:

 a = {"a1","a2","a3"}
b = a
c = b
b[1] = "b1"
c[2] = "c2"
print(a[1])
print(a[2])
print(a[3])

The result will be: "b1" "c2" "a3".

Can I copy variables in another way?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
bizzobaz
  • 95
  • 1
  • 8
  • http://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value – Ovi Faur Jul 11 '14 at 10:29
  • The assignment "b=a" is not a copy - like for instance in c++ a vector copy. Instead the assignment reads "let b point to the same table as a". – lipp Jul 23 '14 at 20:55

0 Answers0