mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
added metatable support
This commit is contained in:
parent
4ddef3ccae
commit
395b02ecbe
10
inspect.lua
10
inspect.lua
@ -116,11 +116,17 @@ function Inspector:putTable(t)
|
||||
comma = self:putComma(comma)
|
||||
self:tabify():putKey(k):puts(' = '):putValue(t[k])
|
||||
end
|
||||
|
||||
local mt = getmetatable(t)
|
||||
if type(mt) == 'table' then
|
||||
comma = self:putComma(comma)
|
||||
self:tabify():puts('<metatable> = '):putValue(mt)
|
||||
end
|
||||
self:up()
|
||||
|
||||
if #dictKeys > 0 then
|
||||
if #dictKeys > 0 then -- dictionary table. Justify closing }
|
||||
self:tabify()
|
||||
elseif length > 0 then
|
||||
elseif length > 0 then -- array tables have one extra space before closing }
|
||||
self:puts(' ')
|
||||
end
|
||||
self:puts('}')
|
||||
|
@ -147,6 +147,19 @@ context( 'inspect', function()
|
||||
|
||||
end)
|
||||
|
||||
test('Should include the metatable as an extra hash attribute', function()
|
||||
local foo = { foo = 1, __tostring = function(k) return 'foo' end }
|
||||
local bar = setmetatable({a = 1}, foo)
|
||||
assert_equal(inspect(bar), [[{
|
||||
a = 1,
|
||||
<metatable> = {
|
||||
__tostring = <function>
|
||||
foo = 1,
|
||||
}
|
||||
}]])
|
||||
end)
|
||||
|
||||
|
||||
end)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user