refactor processRecursive

This commit is contained in:
kikito 2014-08-16 16:35:24 +02:00
parent a1b30ad8a3
commit e74c899b7d

View File

@ -143,18 +143,18 @@ local function makePath(path, key)
return newPath return newPath
end end
local processRecursive = function(object, path, process) local function processRecursive(object, path, process)
local processed = process(object, path) local processed = process(object, path)
if type(processed) == 'table' then if type(processed) == 'table' then
local processed2 = {} local processedCopy = {}
for k,v in pairs(processed) do for k,v in pairs(processed) do
processed2[k] = process(v, makePath(path, k), process) processedCopy[k] = processRecursive(v, makePath(path, k), process)
end end
local mt = process(getmetatable(processed), makePath(path, '<metatable>')) local mt = processRecursive(getmetatable(processed), makePath(path, '<metatable>'), process)
setmetatable(processed2, mt) setmetatable(processedCopy, mt)
processed = processed2 processed = processedCopy
end end
return processed return processed
end end