魔改json库,最后套一层pcall防止致命错误

This commit is contained in:
MrZ626
2020-10-31 21:25:09 +08:00
parent 5745174a9c
commit 6438f16287
5 changed files with 27 additions and 11 deletions

View File

@@ -300,7 +300,9 @@ do--json
error("unexpected type '" .. t .. "'")
end
function json.encode(val) return encode(val) end
function json.encode(val)
return pcall(encode,val)
end
-------------------------------------------------------------------------------
-- Decode
@@ -516,7 +518,7 @@ do--json
decode_error(str, idx, "unexpected character '" .. chr .. "'")
end
function json.decode(str)
local function decode(str)
if type(str) ~= "string" then
error("expected argument of type string, got " .. type(str))
end
@@ -525,6 +527,9 @@ do--json
if idx <= #str then decode_error(str, idx, "trailing garbage") end
return res
end
function json.decode(str)
return pcall(decode,str)
end
end
function copyList(org)
local L={}