Handle write_json/parse_json errors

master
SX 2022-01-01 18:33:04 +02:00
parent cb7ed06979
commit 1d19c2405b
1 changed files with 12 additions and 2 deletions

View File

@ -81,8 +81,18 @@ function core.get_node_light(pos, timeofday)
end
local json = require('mineunit.lib.json')
core.write_json = json.encode
core.parse_json = json.decode
function core.write_json(...)
local args = {...}
local success, result = pcall(function() return json.encode(unpack(args)) end)
return success and result or nil
end
function core.parse_json(...)
local args = {...}
local success, result = pcall(function() return json.decode(unpack(args)) end)
return success and result or nil
end
function core.register_craft(t)
assert.is_table(t, "core.register_craft: table expected, got " .. type(t))