lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Simple. Tables are reference type in Lua, so it's the same table, no matter how many names you give.

To make a copy, you need to do that yourself. And decide whether to do "shallow copy", "deep copy" or something in between.

-asko


G.H. kirjoitti 2.11.2007 kello 15:13:

Hello everyone.

I am pretty curious about this because it looks weird.
You'll see, it appears to be that table.remove() isn't
working properly in Lua 5.1.2 or, at least, it has
unpleasant "secondary effects" when modifying values
previously assigned from _different variables_ :

a = {3,7,8}
return #a
3
b = a
return #b
3
table.remove(b, 1)
return #b
2
return #a
2

I have tried in two different computers obtaining the
same results. Any ideas or teachings about this?
I hope it'd be my imagination...

Thank you in advance -- Mario