refactor out commacontrol method

This commit is contained in:
kikito 2014-09-19 22:35:07 +02:00
parent e35338984d
commit 99deb522f8

View File

@ -202,11 +202,6 @@ function Inspector:tabify()
self:puts(self.newline, string.rep(self.indent, self.level)) self:puts(self.newline, string.rep(self.indent, self.level))
end end
function Inspector:commaControl(needsComma)
if needsComma then self:puts(',') end
return true
end
function Inspector:alreadyVisited(v) function Inspector:alreadyVisited(v)
return self.ids[type(v)][v] ~= nil return self.ids[type(v)][v] ~= nil
end end
@ -251,26 +246,29 @@ function Inspector:putTable(t)
if length >= 1 then self:tabify() end if length >= 1 then self:tabify() end
end end
local needsComma = false local count = 0
for i=1, length do for i=1, length do
needsComma = self:commaControl(needsComma) if count > 0 then self:puts(',') end
self:puts(' ') self:puts(' ')
self:putValue(t[i]) self:putValue(t[i])
count = count + 1
end end
for _,k in ipairs(dictKeys) do for _,k in ipairs(dictKeys) do
needsComma = self:commaControl(needsComma) if count > 0 then self:puts(',') end
self:tabify() self:tabify()
self:putKey(k) self:putKey(k)
self:puts(' = ') self:puts(' = ')
self:putValue(t[k]) self:putValue(t[k])
count = count + 1
end end
if mt then if mt then
needsComma = self:commaControl(needsComma) if count > 0 then self:puts(',') end
self:tabify() self:tabify()
self:puts('<metatable> = ') self:puts('<metatable> = ')
self:putValue(mt) self:putValue(mt)
count = count + 1
end end
end) end)
@ -302,10 +300,12 @@ end
function inspect.inspect(root, options) function inspect.inspect(root, options)
options = options or {} options = options or {}
local depth = options.depth or math.huge local depth = options.depth or math.huge
local process = options.process
local newline = options.newline or '\n' local newline = options.newline or '\n'
local indent = options.indent or ' ' local indent = options.indent or ' '
local process = options.process
if process then if process then
root = processRecursive(process, root, {}) root = processRecursive(process, root, {})
end end