Mistakes at "Cloning Tables" article

This article containts a couple of typos in the scripts that it has. ** is written instead of ".

image
I assume this was supposed to be

original["Shedletsky"].score = 5

image

if type(v) == "table" then

This confused me a lot at first, I actually thought that ** notation had a meaning.
This article seems old, so it must be some bug or something!

The recursive table solution seems a bit over-complicated anyhow. I always created this solution when I wanted to copy tables:

local function DeepCopy(Table)
	local Copy = {}
	for k,v in pairs(Table) do
		if typeof(v) == "table" then
			Copy[k] = DeepCopy(v)
		else
			Copy[k] = v
		end
	end
	return Copy
end

Or, the space-saving method I use:

local function DeepCopy(Table)
	local Copy = {}
	for k,v in pairs(Table) do
		Copy[k] = typeof(v) == "table" and DeepCopy(v) or v
	end
	return Copy
end

Or, if you really wanted to save space:

As incapaxx pointed out to me, foreach is deprecated and shouldn’t be used, but here’s the code nonetheless:

local function DeepCopy(Table)
	local Copy = {}
	table.foreach(Table, function(k,v) Copy[k] = typeof(v) == "table" and DeepCopy(v) or v end)
	return Copy
end
2 Likes

I’ve fixed the syntax issues with the page, and while I’d like to take the time to do a proper re-write of this article I’ll have to put that on the backburner. This article was among the many old wiki-migrated articles.

1 Like

Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.