mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
refactor processRecursive
This commit is contained in:
parent
a1b30ad8a3
commit
e74c899b7d
12
inspect.lua
12
inspect.lua
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user