refactoring of id-related metatables

This commit is contained in:
kikito 2013-09-14 16:12:24 +02:00
parent 67f12d3664
commit 04aea86a32

View File

@ -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
} }
@ -125,9 +120,9 @@ function Inspector:new(t, depth)
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})