From 14a63ac985c9b584e4e946c89db48fb3ff0a4282 Mon Sep 17 00:00:00 2001 From: kikito Date: Sat, 3 Nov 2012 15:17:14 +0100 Subject: [PATCH] transformed inspect into a callable table with _VERSION attribute --- inspect.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/inspect.lua b/inspect.lua index 3e0340c..5d89749 100644 --- a/inspect.lua +++ b/inspect.lua @@ -5,6 +5,9 @@ -- inspired by http://lua-users.org/wiki/TableSerialization ----------------------------------------------------------------------------------------------------------------------- +local inspect ={} +inspect.__VERSION = '1.2.0' + -- Apostrophizes the string if it has quotes, but not aphostrophes -- Otherwise, it returns a regular quoted string local function smartQuote(str) @@ -92,10 +95,7 @@ function Inspector:new(t, depth) tableAppearances = setmetatable({}, {__mode = "k"}) } - setmetatable( inspector, { - __index = Inspector, - __tostring = function(instance) return table.concat(instance.buffer) end - } ) + setmetatable(inspector, {__index = Inspector}) inspector:countTableAppearances(t) @@ -231,9 +231,13 @@ function Inspector:putKey(k) return self:puts( "[" ):putValue(k):puts("]") end -local function inspect(t, depth) - return tostring(Inspector:new(t, depth)) +function Inspector:tostring() + return table.concat(self.buffer) end +setmetatable(inspect, { __call = function(_,t,depth) + return Inspector:new(t, depth):tostring() +end }) + return inspect