mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
refactoring of id-related metatables
This commit is contained in:
parent
67f12d3664
commit
04aea86a32
33
inspect.lua
33
inspect.lua
@ -98,23 +98,18 @@ local function getToStringResultSafely(t, mt)
|
|||||||
return string
|
return string
|
||||||
end
|
end
|
||||||
|
|
||||||
local inspectorMaxIdsMetaTable = {
|
local maxIdsMetaTable = {
|
||||||
__index = function (t, k)
|
__index = function(self, typeName)
|
||||||
if not rawget(t, k) then
|
rawset(self, typeName, 0)
|
||||||
rawset(t, k, 0)
|
|
||||||
end
|
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
local inspectorIdsMetaTable = {
|
local idsMetaTable = {
|
||||||
__index = function (t, k)
|
__index = function (self, typeName)
|
||||||
local v = rawget(t, k)
|
local col = setmetatable({}, {__mode = "kv"})
|
||||||
if not v then
|
rawset(self, typeName, col)
|
||||||
rawset(t, k, setmetatable({}, {__mode = "kv"}))
|
return col
|
||||||
v = rawget(t, k)
|
|
||||||
end
|
|
||||||
return v
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,12 +117,12 @@ local Inspector = {}
|
|||||||
|
|
||||||
function Inspector:new(t, depth)
|
function Inspector:new(t, depth)
|
||||||
local inspector = {
|
local inspector = {
|
||||||
buffer = {},
|
buffer = {},
|
||||||
depth = depth,
|
depth = depth,
|
||||||
level = 0,
|
level = 0,
|
||||||
maxIds = setmetatable({}, inspectorMaxIdsMetaTable),
|
tableAppearances = setmetatable({}, {__mode = "k"}),
|
||||||
ids = setmetatable({}, inspectorIdsMetaTable),
|
maxIds = setmetatable({}, maxIdsMetaTable),
|
||||||
tableAppearances = setmetatable({}, {__mode = "k"})
|
ids = setmetatable({}, idsMetaTable),
|
||||||
}
|
}
|
||||||
|
|
||||||
setmetatable(inspector, {__index = Inspector})
|
setmetatable(inspector, {__index = Inspector})
|
||||||
|
Loading…
Reference in New Issue
Block a user