small refactor

This commit is contained in:
kikito 2012-10-29 20:49:20 +01:00
parent 54ef1b0711
commit 282800b478

View File

@ -27,7 +27,7 @@ local function unescape(str)
end
local function isIdentifier(str)
return string.match( str, "^[_%a][_%a%d]*$" )
return type(str) == 'string' and str:match( "^[_%a][_%a%d]*$" )
end
local function isArrayKey(k, length)
@ -98,14 +98,6 @@ function Inspector:new(v, depth)
return inspector:putValue(v)
end
function Inspector:puts(...)
local args = {...}
for i=1, #args do
table.insert(self.buffer, tostring(args[i]))
end
return self
end
function Inspector:tabify()
self:puts("\n", string.rep(" ", self.level))
return self
@ -119,6 +111,14 @@ function Inspector:down()
self.level = self.level + 1
end
function Inspector:puts(...)
local args = {...}
for i=1, #args do
table.insert(self.buffer, tostring(args[i]))
end
return self
end
function Inspector:putComma(comma)
if comma then self:puts(',') end
return true
@ -202,10 +202,9 @@ function Inspector:putValue(v)
return self
end
function Inspector:putKey(k)
if type(k) == "string" and isIdentifier(k) then
return self:puts(k)
end
if isIdentifier(k) then return self:puts(k) end
return self:puts( "[" ):putValue(k):puts("]")
end