encrypt improvements

This commit is contained in:
kepler155c@gmail.com
2019-06-30 14:47:45 -04:00
parent 67779ab814
commit 721cd840b3
6 changed files with 262 additions and 27 deletions

View File

@@ -0,0 +1,50 @@
local Serializer = { }
local insert = table.insert
local format = string.format
function Serializer.serialize(tbl)
local output = { }
local function recurse(t)
local sType = type(t)
if sType == 'table' then
if next(t) == nil then
insert(output, '{}')
else
insert(output, '{')
local tSeen = {}
for k, v in ipairs(t) do
tSeen[k] = true
recurse(v)
insert(output, ',')
end
for k, v in pairs(t) do
if not tSeen[k] then
if type(k) == 'string' and string.match(k, '^[%a_][%a%d_]*$') then
insert(output, k .. '=')
recurse(v)
insert(output, ',')
else
insert(output, '[')
recurse(k)
insert(output, ']=')
recurse(v)
insert(output, ',')
end
end
end
insert(output, '}')
end
elseif sType == 'string' then
insert(output, format('%q', t))
else
insert(output, tostring(t))
end
end
recurse(tbl)
return table.concat(output)
end
return Serializer