-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersistence.lua
31 lines (28 loc) · 892 Bytes
/
persistence.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
local module = {}
function module.update_format(obj, final_format, updaters)
while obj.format ~= final_format do
local updater = updaters[obj.format]
if updater then
print_debug("file", "update_format: Updating from format %s to %s.", obj.format, updater.output_format)
updater.update(obj)
obj.format = updater.output_format
else
error("Unknown format: "..tostring(obj.format))
end
end
end
function module.json_decode(str, allow_empty)
if allow_empty and (str == nil or str == "") then
return true, nil
else
local success, result = pcall(function()
return json.decode(str)
end)
if success then
return true, result
else
return false, "Failed to decode JSON into object: "..result
end
end
end
return module