diff --git a/inspect.lua b/inspect.lua index 39f43af..7616fc5 100644 --- a/inspect.lua +++ b/inspect.lua @@ -28,6 +28,8 @@ local inspect ={ ]] } +inspect.tostring = _G.tostring + inspect.KEY = setmetatable({}, {__tostring = function() return 'inspect.KEY' end}) inspect.METATABLE = setmetatable({}, {__tostring = function() return 'inspect.METATABLE' end}) @@ -110,7 +112,7 @@ local function getToStringResultSafely(t, mt) local str, ok if type(__tostring) == 'function' then ok, str = pcall(__tostring, t) - str = ok and str or 'error: ' .. tostring(str) + str = ok and str or 'error: ' .. inspect.tostring(str) end if type(str) == 'string' and #str > 0 then return str end end @@ -198,7 +200,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 @@ -224,7 +226,7 @@ function Inspector:getId(v) self.maxIds[tv] = id self.ids[tv][v] = id end - return id + return inspect.tostring(id) end function Inspector:putKey(k) @@ -236,7 +238,7 @@ end function Inspector:putTable(t) if t == inspect.KEY or t == inspect.METATABLE then - self:puts(tostring(t)) + self:puts(inspect.tostring(t)) elseif self:alreadyVisited(t) then self:puts('