diff --git a/inspect.lua b/inspect.lua index 4b654b2..c7179d1 100644 --- a/inspect.lua +++ b/inspect.lua @@ -28,6 +28,8 @@ local inspect ={ ]] } +local tostring = tostring + inspect.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end}) inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end}) @@ -202,7 +204,7 @@ function Inspector:puts(...) local len = #buffer for i=1, #args do len = len + 1 - buffer[len] = tostring(args[i]) + buffer[len] = args[i] end end @@ -228,7 +230,7 @@ function Inspector:getId(v) self.maxIds[tv] = id self.ids[tv][v] = id end - return id + return tostring(id) end function Inspector:putKey(k) diff --git a/spec/inspect_spec.lua b/spec/inspect_spec.lua index 78b0a7b..23868f0 100644 --- a/spec/inspect_spec.lua +++ b/spec/inspect_spec.lua @@ -417,4 +417,13 @@ describe( 'inspect', function() end) end) end) + + it('allows changing the global tostring', function() + local save = _G.tostring + _G.tostring = inspect + local s = tostring({1, 2, 3}) + _G.tostring = save + assert.equals("{ 1, 2, 3 }", s) + end) + end)