2 Licensed according to the included 'LICENSE' document
3 Author: Thomas Harning Jr <harningt@gmail.com>
7 local tostring = tostring
9 local getmetatable
, setmetatable
= getmetatable
, setmetatable
12 local is_52
= _VERSION
== "Lua 5.2"
19 local function foreach(tab
, func
)
20 for k
, v
in pairs(tab
) do
24 local function printValue(tab
, name
)
26 local function doPrint(key
, value
, space
)
28 if type(value
) == 'table' then
30 print(space
.. key
.. '= <' .. parsed
[value
] .. '>')
33 print(space
.. key
.. '= {')
35 foreach(value
, function(key
, value
) doPrint(key
, value
, space
) end)
38 if type(value
) == 'string' then
39 value
= '[[' .. tostring(value
) .. ']]'
41 print(space
.. key
.. '=' .. tostring(value
))
47 local function clone(t
)
49 for k
,v
in pairs(t
) do
55 local function merge(t
, from
, ...)
59 for k
,v
in pairs(from
) do
65 -- Function to insert nulls into the JSON stream
70 -- Marker for 'undefined' values
71 local function undefined()
78 Return's true if the metatable marks it as an array..
79 Or false if it has no array component at all
80 Otherwise nil to get the normal detection component working
82 local function IsArray(value
)
83 if type(value
) ~= 'table' then return false end
84 local ret
= getmetatable(value
) == ArrayMT
86 if #value
== 0 then return false end
91 local function InitArray(array
)
92 setmetatable(array
, ArrayMT
)
98 local function isCall(value
)
99 return CallMT
== getmetatable(value
)
102 local function buildCall(name
, ...)
105 parameters
= {n
= select('#', ...), ...}
107 return setmetatable(callData
, CallMT
)
110 local function decodeCall(callData
)
111 if not isCall(callData
) then return nil end
112 return callData
.name
, callData
.parameters
116 printValue
= printValue
,
120 undefined
= undefined
,
122 InitArray
= InitArray
,
124 buildCall
= buildCall
,
125 decodeCall
= decodeCall
129 _G
.json
= _G
.json
or {}
130 _G
.json
.util
= json_util