forked from premake/premake-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonwrapper.lua
More file actions
59 lines (42 loc) · 1.17 KB
/
jsonwrapper.lua
File metadata and controls
59 lines (42 loc) · 1.17 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
--
-- jsonwrapper.lua
-- Provides JSON encoding and decoding API by wrapping a third-party JSON library
-- Copyright (c) 2017 Jason Perkins and the Premake project
--
json = {}
local implementation = dofile('json.lua')
local err
json.implementation = implementation
function implementation.assert(condition, message)
if not condition then
err = message
end
-- The JSON library we're using assumes that encode error handlers will
-- abort on error. It doesn't have the same assumption for decode error
-- handlers, but we're using this same function for both.
assert(condition, message)
end
function json.encode(value)
err = nil
local success, result = pcall(implementation.encode, implementation, value)
if not success then
return nil, err
end
return result
end
function json.encode_pretty(value)
err = nil
local success, result = pcall(implementation.encode_pretty, implementation, value)
if not success then
return nil, err
end
return result
end
function json.decode(value)
err = nil
local success, result = pcall(implementation.decode, implementation, value)
if not success then
return nil, err
end
return result
end