this is what a deep copy function is supposed to look like, right? i'm not forgetting something obvious? 

function deep_copy(other)
if tostr(other) != "[table]" then
return other
end

t = {}
for k, v in pairs(other) do
t[k] = deep_copy(v)
end
return t
end

this is what a deep copy function is supposed to look like, right? i'm not forgetting something obvious? 

@shoofle
Looks conceptually right, but some implementation questions:

What language is this?

Does your language have any notion of types? Looking for [table] as a string is sketchy. What if your value is the literal string [table]?

If you have an array, is the "return other" going to return a copy of the array, or a reference?

this is what a deep copy function is supposed to look like, right? i'm not forgetting something obvious? 

@polyphonic haha i actually just updated it to check against 'type' instead of 'tostr'; this is lua and that part SHOULD work. i'll try it aggain with the type check

Follow

this is what a deep copy function is supposed to look like, right? i'm not forgetting something obvious? 

@shoofle
I suspected lua. Lua is pretty cool!

It can easily be confused with javascript, especially when you have to deal with them both.

Except lua is actually nice under the hood! 😅

Looking up lua specific examples, you still have corner cases If your table is cyclical or recursive. Also you haven't covered metatable copying.

But I suspect you don't require these features today.

Sign in to participate in the conversation
Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!