From 1514d8682871a1a4971a094d3acc3189dc743d21 Mon Sep 17 00:00:00 2001 From: kikito Date: Sun, 20 Jan 2013 17:23:36 +0100 Subject: [PATCH] fix overflow when a table is its own metatable. References #4 --- inspect.lua | 2 +- spec/inspect_spec.lua | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/inspect.lua b/inspect.lua index 5d89749..f01a6b2 100644 --- a/inspect.lua +++ b/inspect.lua @@ -110,10 +110,10 @@ function Inspector:countTableAppearances(t) self:countTableAppearances(k) self:countTableAppearances(v) end + self:countTableAppearances(getmetatable(t)) else self.tableAppearances[t] = self.tableAppearances[t] + 1 end - self:countTableAppearances(getmetatable(t)) end end diff --git a/spec/inspect_spec.lua b/spec/inspect_spec.lua index 9df0932..174a735 100644 --- a/spec/inspect_spec.lua +++ b/spec/inspect_spec.lua @@ -191,6 +191,15 @@ describe( 'inspect', function() } }]]) end) + + it('accepts a table that is its own metatable without stack overflowing', function() + local x = {} + setmetatable(x,x) + assert.equals(inspect(x), [[<1>{ + = +}]]) + end) + end) end) end)