made serialization have an extra param for display
This commit is contained in:
parent
b370a90618
commit
560cd4e0c7
@ -3,7 +3,7 @@ local local_pairs=function(tbl)
|
|||||||
local mt=getmetatable(tbl)
|
local mt=getmetatable(tbl)
|
||||||
return (mt and mt.__pairs or pairs)(tbl)
|
return (mt and mt.__pairs or pairs)(tbl)
|
||||||
end
|
end
|
||||||
function serial.serialize(value)
|
function serial.serialize(value,af) -- serialize *value* into a string. If *af* is true, allow functions. This breaks unserialization.
|
||||||
local kw={["and"]=true,["break"]=true,["do"]=true,["else"]=true,["elseif"]=true,["end"]=true,["false"]=true,["for"]=true,["function"]=true,["goto"]=true,["if"]=true,["in"]=true,["local"]=true,["nil"]=true,["not"]=true,["or"]=true,["repeat"]=true,["return"]=true,["then"]=true,["true"]=true,["until"]=true,["while"]=true}
|
local kw={["and"]=true,["break"]=true,["do"]=true,["else"]=true,["elseif"]=true,["end"]=true,["false"]=true,["for"]=true,["function"]=true,["goto"]=true,["if"]=true,["in"]=true,["local"]=true,["nil"]=true,["not"]=true,["or"]=true,["repeat"]=true,["return"]=true,["then"]=true,["true"]=true,["until"]=true,["while"]=true}
|
||||||
local id="^[%a_][%w_]*$"
|
local id="^[%a_][%w_]*$"
|
||||||
local ts={}
|
local ts={}
|
||||||
@ -35,10 +35,12 @@ function serial.serialize(value)
|
|||||||
r=r.."="..s(v,l+1) end end
|
r=r.."="..s(v,l+1) end end
|
||||||
ts[v]=nil
|
ts[v]=nil
|
||||||
return (r or "{").."}"
|
return (r or "{").."}"
|
||||||
|
elseif t=="function" and af then
|
||||||
|
return tostring(v)
|
||||||
else error("ut "..t) end end
|
else error("ut "..t) end end
|
||||||
return s(value, 1)
|
return s(value, 1)
|
||||||
end
|
end
|
||||||
function serial.unserialize(data)
|
function serial.unserialize(data) -- return *data*, but unserialized
|
||||||
checkArg(1, data, "string")
|
checkArg(1, data, "string")
|
||||||
local result, reason = load("return " .. data, "=data", _, {math={huge=math.huge}})
|
local result, reason = load("return " .. data, "=data", _, {math={huge=math.huge}})
|
||||||
if not result then return nil, reason end
|
if not result then return nil, reason end
|
||||||
|
Loading…
Reference in New Issue
Block a user