mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
Merge pull request #21 from Nymphium/get_t_length_with_rawlen
avoid __len metamethod
This commit is contained in:
commit
144dec31f7
@ -31,6 +31,10 @@ local inspect ={
|
|||||||
inspect.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end})
|
inspect.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end})
|
||||||
inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end})
|
inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end})
|
||||||
|
|
||||||
|
local rawlen = rawlen or function(t)
|
||||||
|
return #t
|
||||||
|
end
|
||||||
|
|
||||||
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
-- Apostrophizes the string if it has quotes, but not aphostrophes
|
||||||
-- Otherwise, it returns a regular quoted string
|
-- Otherwise, it returns a regular quoted string
|
||||||
local function smartQuote(str)
|
local function smartQuote(str)
|
||||||
@ -84,7 +88,7 @@ local function sortKeys(a, b)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function getNonSequentialKeys(t)
|
local function getNonSequentialKeys(t)
|
||||||
local keys, length = {}, #t
|
local keys, length = {}, rawlen(t)
|
||||||
for k,_ in pairs(t) do
|
for k,_ in pairs(t) do
|
||||||
if not isSequenceKey(k, length) then table.insert(keys, k) end
|
if not isSequenceKey(k, length) then table.insert(keys, k) end
|
||||||
end
|
end
|
||||||
@ -232,7 +236,7 @@ function Inspector:putTable(t)
|
|||||||
if self.tableAppearances[t] > 1 then self:puts('<', self:getId(t), '>') end
|
if self.tableAppearances[t] > 1 then self:puts('<', self:getId(t), '>') end
|
||||||
|
|
||||||
local nonSequentialKeys = getNonSequentialKeys(t)
|
local nonSequentialKeys = getNonSequentialKeys(t)
|
||||||
local length = #t
|
local length = rawlen(t)
|
||||||
local mt = getmetatable(t)
|
local mt = getmetatable(t)
|
||||||
local toStringResult = getToStringResultSafely(t, mt)
|
local toStringResult = getToStringResultSafely(t, mt)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user