Difference between table.Copy


local t0 = {"a", "b", "c"} 

//What's the difference between
local t1 = table.Copy( t0 ) 
//And
local t1 = t0

table.Copy copies all the values to a new table by value.
Saying t1 = t0 is essentially copying by reference, while you make a change to t1, it will change t0 just the same.

I believe.

I don’t know if the reason is right, but the result is.

Basically, it works like this.

[lua]
local t0 = {“a”,“b”}
local t1 = table.Copy(t0)
local t2 = t0

table.insert(t0,“c”)

print(string.concat(t1))
print(string.concat(t2))[/lua]



>a b
>a b c


think of it as making a shortcut (local t1 = t0) to a file on your computer versus copying (local t1 = table.Copy(t0)) the entire file

Yes. Basically:
[lua]
local mytable = {}
[/lua]

{} creates a new, nameless table object stored somewhere in memory.

mytable is simply a name that refers to this object. Think of the = as saying “the name on the left should refer to the object on the right”.

A name can only refer to one object at a time. However, the opposite isn’t true: a single object can have many names.

by doing this:
[lua]
sametable = mytable
[/lua]
You’re saying you want the name “sametable” to refer to the same object the name “mytable” is referring to.