Re: Overwrite Data
Posted: Tue Oct 14, 2014 3:24 am
Yeah that is exactly what deepCopy does, your simpler shallow copy does the following
while deep copy
I think that Robins code breaks when you do this though:
Since it can't handle table loops, if you wanted to do this you would first have to detect the loops with parsing... and that is really hard... maybe there is a library to do this
Code: Select all
t = {
a = {
b = "hello"
}
}
for k,v in pairs(t) do
x[k] = t[k]
end
x.a.b = "bye"
print(t.a.b) --"bye"
print(t==x) --"false"
print(t.a == x.a) --"true"
Code: Select all
t = {
a = {
b = "hello"
}
}
x = deepCopy(t)
x.a.b = "bye"
print(t.a.b) --"hello"
print(t == x) --"false"
print (t.a == x.a) --"false"
Code: Select all
t = {
a = t
}
x = deepCopy(t)