mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
refactorized putTable & comma control
This commit is contained in:
parent
845a045962
commit
4ddef3ccae
21
inspect.lua
21
inspect.lua
@ -92,28 +92,29 @@ function Inspector:down()
|
|||||||
self.level = self.level + 1
|
self.level = self.level + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Inspector:putComma(comma)
|
||||||
|
if comma then self:puts(',') end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
function Inspector:putTable(t)
|
function Inspector:putTable(t)
|
||||||
if self.level >= self.depth then
|
if self.level >= self.depth then
|
||||||
self:puts('{...}')
|
self:puts('{...}')
|
||||||
else
|
else
|
||||||
local length, needsComma = #t, false
|
local length = #t
|
||||||
|
local comma = false
|
||||||
self:puts('{')
|
self:puts('{')
|
||||||
self:down()
|
self:down()
|
||||||
for i=1, length do
|
for i=1, length do
|
||||||
if needsComma then self:puts(',') end
|
comma = self:putComma(comma)
|
||||||
needsComma = true
|
|
||||||
self:puts(' '):putValue(t[i])
|
self:puts(' '):putValue(t[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
local dictKeys = getDictionaryKeys(t)
|
local dictKeys = getDictionaryKeys(t)
|
||||||
|
|
||||||
for _,k in ipairs(dictKeys) do
|
for _,k in ipairs(dictKeys) do
|
||||||
if needsComma then self:puts(',') end
|
comma = self:putComma(comma)
|
||||||
needsComma = true
|
self:tabify():putKey(k):puts(' = '):putValue(t[k])
|
||||||
self:tabify()
|
|
||||||
self:addKey(k)
|
|
||||||
self:puts(' = ')
|
|
||||||
self:putValue(t[k])
|
|
||||||
end
|
end
|
||||||
self:up()
|
self:up()
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ function Inspector:putValue(v)
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
function Inspector:addKey(k)
|
function Inspector:putKey(k)
|
||||||
if type(k) == "string" and isIdentifier(k) then
|
if type(k) == "string" and isIdentifier(k) then
|
||||||
return self:puts(k)
|
return self:puts(k)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user