Posted 11 July 2016 - 12:21 PM
_G.table['clone'] = {}
_G.table['clone']['table'] = function(tab, excludes)
local cloneTable = {}
excludes = excludes or {}
for key, value in pairs(tab) do
if type(value) == 'table' then
if not excludes[value] then
excludes[value] = cloneTable[key]
cloneTable[key] = table.clone(value, excludes) -- Endless loop, by _G._G -> _G._G._G .... _G._G._G._G._G.ERROR
else
cloneTable[key] = excludes[value]
end
elseif type(value) == 'function' then
cloneTable[key] = function(...) return value(...) end
else
cloneTable[key] = value
end
end
return cloneTable
end
setmetatable(_G.table['clone'], {__call = function(_, ...)
return _G.table['clone']['table'](...)
end, __metatable = 'attempt to acess a protected metatable'})
It loops endless, by cloning _G, how can I prevent it?