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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
--- SPDX-License-Identifier: MIT
---@meta rsjson
local rsjson =
--- Represents the JSON `null` value.
--- This can be used in the place of
--- `nil` to represent empty values.
---
---@class rsjson.null: lightuserdata
rsjson. = nil
--- A metatable attachable to a Lua table to systematically encode
--- it as Array (instead of Map). As a result, encoded Array will
--- contain only sequence part of the table, with the same length
--- as the # operator on that table.
---
---@class rsjson.array_mt: table
rsjson. = nil
---@class (exact) rsjson.EncodeConfig: userdata
---
---@field indent number The number of `prefix` to indent lines
---@field prefix string The string to use for indentation
---@field sort_keys boolean Sort JSON keys
---@field encode_empty_tables_as_array boolean Convert empty tables to empty arrays
---@field detect_mixed_tables boolean Detect mixed sequence and key tables
---@field deny_unsupported_types boolean Error on unsupported types (functions, threads, etc)
---@field deny_recursive_tables boolean Error on recursive tables.
rsjson. =
--- Create a new `rsjson.EncodeConfig`
---
---@return rsjson.EncodeConfig
--- Set the indent level
---
---@param indent? integer
---
---@return self
--- Set the indent prefix string
---
---@param prefix? string
---
---@return self
--- Set whether to deny serializing unsupported Lua types.
---
--- This includes functions, threads, lightuserdata, and errors
---
---@param deny? boolean
---
---@return self
--- Set whether to deny serializing recursive tables.
---
--- If true, an attempt to serialize a recursive table will cause an error.
--- Otherwise subsequent attempts to serialize the same table will be ignored.
---
---@param deny? boolean
---
---@return self
--- Whether to sort keys in order.
---
---@param enable? boolean
---
---@return self
--- Whether to encode empty tables as arrays.
---
--- If false, empty tables will be serialized as maps.
---
---@param enable? boolean
---
---@return self
--- Whether to detext mixed tables.
---
--- When false, a table with a non-zero length (with one or more borders) will
--- be always encoded as an array.
---@param enable? boolean
---
---@return self
---@class (exact) rsjson.DecodeConfig: userdata
---
---@field null boolean Convert `nil` to `rsjson.null`
---@field cast_u64_to_f64 boolean Convert u64 numbers to f64 if they overflow i64
---@field array_metatable boolean Set the metatable of JSON array tables to `mlua::Lua::array_metatable`
rsjson. =
--- Create a new `rsjson.DecodeConfig`
---
---@return rsjson.DecodeConfig
--- Whether to decode JSON `null` to `rsjson.null` or `nil`
---
---@param enable boolean
---
---@return self
--- Whether to cast u64 JSON numbers to floats.
---
---@param enable boolean
---
---@return self
--- Whether to set the metatable of JSON arrays to `rsjson.array_mt`.s
---
---@param enable boolean
---
---@return self
--- Serialize a Lua object into a JSON string
---
---@param obj any Any Lua object
---@param config? rsjson.EncodeConfig
---
---@return string # The serialized Lua object
--- Deserialize a JSON string into a Lua object
---
---@param str string The JSON string
---@param config? rsjson.DecodeConfig
---
---@return any # The deserialized JSON object
return rsjson