Module:User:Theknightwho/test2

local string = string local format = string.format local sub = string.sub

local table = table local concat = table.concat local sort = table.sort

return function(object) local doneTable = {} local doneObj = {} local ct = {} local function sorter(a, b)		local ta, tb = type(a), type(b) if ta ~= tb then return ta < tb		end if ta == "string" or ta == "number" then return a < b		end if ta == "boolean" then return tostring(a) < tostring(b) end return false -- Incomparable end local function _dumpObject(object, expandTable) local tp = type(object) if tp == "number" or tp == "nil" or tp == "boolean" then return tostring(object) elseif tp == "string" then return format("%q", object) elseif tp == "table" then if not doneObj[object] then local s = tostring(object) if s == "table" then ct[tp] = (ct[tp] or 0) + 1 doneObj[object] = "table#" .. ct[tp] else doneObj[object] = s					doneTable[object] = true end end if doneTable[object] or not expandTable then return doneObj[object] end doneTable[object] = true local object_len = 0 for key in pairs(object) do				object_len = object_len + 1 end

local ret = {doneObj[object], " {"} local mt = getmetatable(object) if mt then ret[#ret + 1] = "metatable = " ret[#ret + 1] = _dumpObject(mt, true) if object_len > 0 then ret[#ret + 1] = ", " end end local doneKeys = {} for key, value in ipairs(object) do				doneKeys[key] = true ret[#ret + 1] = _dumpObject(value, true) if key < object_len then ret[#ret + 1] = ", " end end local extra_keys = {} for key in pairs(object) do				if not doneKeys[key] then extra_keys[#extra_keys + 1] = key end end sort(extra_keys, sorter) local extra_keys_len = #extra_keys for i = 1, extra_keys_len do				local key = extra_keys[i] ret[#ret + 1] = "[" ret[#ret + 1] = _dumpObject(key, true) ret[#ret + 1] = "] = " ret[#ret + 1] = _dumpObject(object[key], true) if i < extra_keys_len then ret[#ret + 1] = ", " end end ret[#ret + 1] = "}" return concat(ret) else if not doneObj[object] then ct[tp] = (ct[tp] or 0) + 1 doneObj[object] = tostring(object) .. "#" .. ct[tp] end return doneObj[object] end end return _dumpObject(object, true) end