mirror of
https://github.com/kikito/inspect.lua.git
synced 2024-12-15 14:34:21 +00:00
fixed metatable-related loop when a table is its own index. References #4
This commit is contained in:
parent
1514d86828
commit
2b502e1a81
@ -64,7 +64,7 @@ local function getDictionaryKeys(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function getToStringResultSafely(t, mt)
|
local function getToStringResultSafely(t, mt)
|
||||||
local __tostring = type(mt) == 'table' and mt.__tostring
|
local __tostring = type(mt) == 'table' and rawget(mt, '__tostring')
|
||||||
local string, status
|
local string, status
|
||||||
if type(__tostring) == 'function' then
|
if type(__tostring) == 'function' then
|
||||||
status, string = pcall(__tostring, t)
|
status, string = pcall(__tostring, t)
|
||||||
|
@ -192,14 +192,26 @@ describe( 'inspect', function()
|
|||||||
}]])
|
}]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('accepts a table that is its own metatable without stack overflowing', function()
|
describe('When a table is its own metatable', function()
|
||||||
local x = {}
|
it('accepts a table that is its own metatable without stack overflowing', function()
|
||||||
setmetatable(x,x)
|
local x = {}
|
||||||
assert.equals(inspect(x), [[<1>{
|
setmetatable(x,x)
|
||||||
|
assert.equals(inspect(x), [[<1>{
|
||||||
<metatable> = <table 1>
|
<metatable> = <table 1>
|
||||||
}]])
|
}]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('can invoke the __tostring method without stack overflowing', function()
|
||||||
|
local t = {}
|
||||||
|
t.__index = t
|
||||||
|
setmetatable(t,t)
|
||||||
|
assert.equals(inspect(t), [[<1>{
|
||||||
|
__index = <table 1>,
|
||||||
|
<metatable> = <table 1>
|
||||||
|
}]])
|
||||||
|
end)
|
||||||
|
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user