|
|
@ -20,7 +20,7 @@ local function isfinite(x)
|
|
|
|
return x ~= math.huge and x ~= -math.huge and x == x
|
|
|
|
return x ~= math.huge and x ~= -math.huge and x == x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function keys(k, i)
|
|
|
|
local function keys(k, i, mode)
|
|
|
|
local t = type(k)
|
|
|
|
local t = type(k)
|
|
|
|
|
|
|
|
|
|
|
|
if t == 'boolean' then
|
|
|
|
if t == 'boolean' then
|
|
|
@ -39,13 +39,13 @@ local function keys(k, i)
|
|
|
|
|
|
|
|
|
|
|
|
return "["..k.."]"
|
|
|
|
return "["..k.."]"
|
|
|
|
elseif t == 'table' then
|
|
|
|
elseif t == 'table' then
|
|
|
|
return "["..dopack(k, i+1).."]"
|
|
|
|
return "["..dopack(k, i+1, mode).."]"
|
|
|
|
else
|
|
|
|
else
|
|
|
|
error("Can't serialize.pack() table with key `"..tostring(k).."'.")
|
|
|
|
error("Can't serialize.pack() table with key `"..tostring(k).."'.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function vals(v, i)
|
|
|
|
local function vals(v, i, mode)
|
|
|
|
local t = type(v)
|
|
|
|
local t = type(v)
|
|
|
|
|
|
|
|
|
|
|
|
if t == 'boolean' then
|
|
|
|
if t == 'boolean' then
|
|
|
@ -59,7 +59,7 @@ local function vals(v, i)
|
|
|
|
|
|
|
|
|
|
|
|
return tostring(v)
|
|
|
|
return tostring(v)
|
|
|
|
elseif t == 'table' then
|
|
|
|
elseif t == 'table' then
|
|
|
|
return dopack(v, i+1)
|
|
|
|
return dopack(v, i+1, mode)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
error("Can't serialize.pack() table with value `"..tostring(v).."'.")
|
|
|
|
error("Can't serialize.pack() table with value `"..tostring(v).."'.")
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -78,7 +78,7 @@ function dopack(o, i, mode)
|
|
|
|
goto skip
|
|
|
|
goto skip
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
fields[#fields + 1] = ("%s%s"):format(is, vals(v, i))
|
|
|
|
fields[#fields + 1] = ("%s%s"):format(is, vals(v, i, mode))
|
|
|
|
|
|
|
|
|
|
|
|
::skip:: seen[k] = true
|
|
|
|
::skip:: seen[k] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -89,7 +89,7 @@ function dopack(o, i, mode)
|
|
|
|
goto skip
|
|
|
|
goto skip
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local f = ("%s%s = %s"):format(is, keys(k, i), vals(v, i))
|
|
|
|
local f = ("%s%s = %s"):format(is, keys(k, i, mode), vals(v, i, mode))
|
|
|
|
|
|
|
|
|
|
|
|
fields[#fields + 1] = f
|
|
|
|
fields[#fields + 1] = f
|
|
|
|
|
|
|
|
|
|
|
|