function dump(var) local res = "" if type(var) == "string" then return '"' .. var .. '"' elseif type(var) == "number" then return "" .. var elseif type(var) == "function" then return '@' elseif type(var) == "boolean" then if var then return "true" else return "false" end elseif type(var) == "nil" then return nil elseif type(var) == "table" then -- ipairs - indexed pairs -- pairs - key named pairs res = "{" if not indexed then for k, v in pairs(var) do res = res .. dump(k) .. '=' .. dump(v) .. ',' end end res = string.sub(res, 1, string.len(res)-1) res = res .. "}" else print(type(var)) end return res end local socket = {my="test",table="example", "1", "2", "3"} print(dump(socket))
Еще проще
function dump(o) if type(o) == 'table' then local s = '{ ' for k,v in pairs(o) do if type(k) ~= 'number' then k = '"'..k..'"' end s = s .. '['..k..'] = ' .. dump(v) .. ',' end return s .. '} ' else return tostring(o) end end