mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
changed function processRecursive
This commit is contained in:
parent
89588bd4d9
commit
1f54536b56
41
inspect.lua
41
inspect.lua
@ -164,34 +164,29 @@ local function makePath(path, ...)
|
|||||||
return newPath
|
return newPath
|
||||||
end
|
end
|
||||||
|
|
||||||
local function processRecursive(process, item, path)
|
local function processRecursive(process, item, path, visited)
|
||||||
local visited = {}
|
|
||||||
|
|
||||||
local function processRecursive2(item2, path2)
|
if item == nil then return nil end
|
||||||
if item2 == nil then return nil end
|
if visited[item] then return visited[item] end
|
||||||
if visited[item2] then return visited[item2] end
|
|
||||||
|
|
||||||
local processed = process(item2, path2)
|
local processed = process(item, path)
|
||||||
if type(processed) == 'table' then
|
if type(processed) == 'table' then
|
||||||
local processedCopy = {}
|
local processedCopy = {}
|
||||||
visited[item2] = processedCopy
|
visited[item] = processedCopy
|
||||||
local processedKey
|
local processedKey
|
||||||
|
|
||||||
for k,v in pairs(processed) do
|
for k,v in pairs(processed) do
|
||||||
processedKey = processRecursive2(k, makePath(path2, k, inspect.KEY))
|
processedKey = processRecursive(process, k, makePath(path, k, inspect.KEY), visited)
|
||||||
if processedKey ~= nil then
|
if processedKey ~= nil then
|
||||||
processedCopy[processedKey] = processRecursive2(v, makePath(path2, processedKey))
|
processedCopy[processedKey] = processRecursive(process, v, makePath(path, processedKey), visited)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local mt = processRecursive2(getmetatable(processed), makePath(path2, inspect.METATABLE))
|
|
||||||
setmetatable(processedCopy, mt)
|
|
||||||
processed = processedCopy
|
|
||||||
end
|
end
|
||||||
return processed
|
|
||||||
end
|
|
||||||
|
|
||||||
return processRecursive2(item, path)
|
local mt = processRecursive(process, getmetatable(processed), makePath(path, inspect.METATABLE), visited)
|
||||||
|
setmetatable(processedCopy, mt)
|
||||||
|
processed = processedCopy
|
||||||
|
end
|
||||||
|
return processed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -324,7 +319,7 @@ function inspect.inspect(root, options)
|
|||||||
local process = options.process
|
local process = options.process
|
||||||
|
|
||||||
if process then
|
if process then
|
||||||
root = processRecursive(process, root, {})
|
root = processRecursive(process, root, {}, {})
|
||||||
end
|
end
|
||||||
|
|
||||||
local inspector = setmetatable({
|
local inspector = setmetatable({
|
||||||
|
Loading…
Reference in New Issue
Block a user