Skip to content

Commit dc95816

Browse files
authored
Update lljson definitions from SLua's lljson rework PR
Update lljson definitions from Major lljson rework to make round-trippable serialization easier slua#61
1 parent 365fe6b commit dc95816

File tree

5 files changed

+162
-75
lines changed

5 files changed

+162
-75
lines changed

generated/slua_default.d.luau

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ export type OsDateTime = {
6060
yday: number?,
6161
isdst: boolean?,
6262
}
63+
type LLJsonEncodeOptions = {
64+
tight: boolean?,
65+
skip_tojson: boolean?,
66+
allow_sparse: boolean?,
67+
replacer: ((key: any, value: any, parent: {}?) -> any)?,
68+
}
69+
type LLJsonDecodeReviverWithoutPath = (key: string | number, value: any, parent: {}?, ctx: {}) -> any
70+
type LLJsonDecodeOptionsWithoutPath = {
71+
track_path: false?,
72+
reviver: LLJsonDecodeReviverWithoutPath?,
73+
} | LLJsonDecodeReviverWithoutPath
74+
type LLJsonDecodeOptionsWithPath = {
75+
track_path: true,
76+
reviver: (key: string | number, value: any, parent: {}?, ctx: {path: {string | number}}) -> any
77+
}
78+
type LLJsonDecodeOptions = LLJsonDecodeOptionsWithoutPath | LLJsonDecodeOptionsWithPath
6379

6480
declare extern type DetectedEvent with
6581
index: number
@@ -256,15 +272,15 @@ declare llbase64: {
256272

257273
declare lljson: {
258274
null: any,
259-
empty_array_mt: { [any]: any },
260-
array_mt: { [any]: any },
261-
empty_array: any,
262-
_NAME: string,
263-
_VERSION: string,
264-
encode: (value: any) -> string,
265-
decode: (json: string) -> any,
266-
slencode: (value: any, tight: boolean?) -> string,
267-
sldecode: (json: string) -> any,
275+
remove: any,
276+
array_mt: {__jsonhint: string},
277+
object_mt: {__jsonhint: string},
278+
empty_array: {},
279+
empty_object: {},
280+
encode: (value: any, options: LLJsonEncodeOptions?) -> string,
281+
decode: (json: string, options: LLJsonDecodeOptions?) -> any,
282+
slencode: (value: any, options: LLJsonEncodeOptions?) -> string,
283+
sldecode: (json: string, options: LLJsonDecodeOptions?) -> any,
268284
}
269285

270286

generated/slua_default.docs.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,27 +256,27 @@
256256
"learn_more_link": "https://create.secondlife.com/script/learn-slua/json/"
257257
},
258258
"@sl-slua/global/lljson.null": {
259-
"documentation": "A constant to pass for null to json encode",
259+
"documentation": "A constant to pass for null to json encode.",
260260
"learn_more_link": "https://create.secondlife.com/script/learn-slua/json/"
261261
},
262-
"@sl-slua/global/lljson.empty_array_mt": {
263-
"documentation": "Value: {}<br>Metatable for declaring table as an empty array for json encode",
262+
"@sl-slua/global/lljson.remove": {
263+
"documentation": "A constant to return from a reviver/replacer replacer function to omit this item.",
264264
"learn_more_link": "https://create.secondlife.com/script/learn-slua/json/"
265265
},
266266
"@sl-slua/global/lljson.array_mt": {
267-
"documentation": "Value: {}<br>Metatable for declaring table as an array for json encode",
267+
"documentation": "Value: {__jsonhint = \"array\"}<br>Metatable for declaring table as an array for json encode.",
268268
"learn_more_link": "https://create.secondlife.com/script/learn-slua/json/"
269269
},
270-
"@sl-slua/global/lljson.empty_array": {
271-
"documentation": "A constant to pass for an empty array to json encode",
270+
"@sl-slua/global/lljson.object_mt": {
271+
"documentation": "Value: {__jsonhint = \"object\"}<br>Metatable for declaring table as an object for json encode.",
272272
"learn_more_link": "https://create.secondlife.com/script/learn-slua/json/"
273273
},
274-
"@sl-slua/global/lljson._NAME": {
275-
"documentation": "Value: \"lljson\"<br>Name of the lljson library",
274+
"@sl-slua/global/lljson.empty_array": {
275+
"documentation": "Value: setmetatable({}, lljson.array_mt}<br>A constant to pass for an empty array to json encode.",
276276
"learn_more_link": "https://create.secondlife.com/script/learn-slua/json/"
277277
},
278-
"@sl-slua/global/lljson._VERSION": {
279-
"documentation": "Value: \"2.1.0.11\"<br>Version of the lljson library",
278+
"@sl-slua/global/lljson.empty_object": {
279+
"documentation": "Value: setmetatable({}, lljson.object_mt}<br>A constant to pass for an empty object to json encode.",
280280
"learn_more_link": "https://create.secondlife.com/script/learn-slua/json/"
281281
},
282282
"@sl-slua/global/lljson.encode": {

generated/slua_keywords_pretty.xml

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -235,53 +235,53 @@ export type rotation = quaternion</string>
235235
<key>value</key>
236236
<string>false</string>
237237
</map>
238-
<key>lljson._NAME</key>
238+
<key>lljson.array_mt</key>
239239
<map>
240240
<key>tooltip</key>
241-
<string>Name of the lljson library</string>
241+
<string>Metatable for declaring table as an array for json encode.</string>
242242
<key>type</key>
243-
<string>string</string>
243+
<string>{__jsonhint: string}</string>
244244
<key>value</key>
245-
<string>"lljson"</string>
245+
<string>{__jsonhint = "array"}</string>
246246
</map>
247-
<key>lljson._VERSION</key>
247+
<key>lljson.empty_array</key>
248248
<map>
249249
<key>tooltip</key>
250-
<string>Version of the lljson library</string>
250+
<string>A constant to pass for an empty array to json encode.</string>
251251
<key>type</key>
252-
<string>string</string>
252+
<string>{}</string>
253253
<key>value</key>
254-
<string>"2.1.0.11"</string>
254+
<string>setmetatable({}, lljson.array_mt}</string>
255255
</map>
256-
<key>lljson.array_mt</key>
256+
<key>lljson.empty_object</key>
257257
<map>
258258
<key>tooltip</key>
259-
<string>Metatable for declaring table as an array for json encode</string>
259+
<string>A constant to pass for an empty object to json encode.</string>
260260
<key>type</key>
261-
<string>{ [any]: any }</string>
262-
<key>value</key>
263261
<string>{}</string>
262+
<key>value</key>
263+
<string>setmetatable({}, lljson.object_mt}</string>
264264
</map>
265-
<key>lljson.empty_array</key>
265+
<key>lljson.null</key>
266266
<map>
267267
<key>tooltip</key>
268-
<string>A constant to pass for an empty array to json encode</string>
268+
<string>A constant to pass for null to json encode.</string>
269269
<key>type</key>
270270
<string>any</string>
271271
</map>
272-
<key>lljson.empty_array_mt</key>
272+
<key>lljson.object_mt</key>
273273
<map>
274274
<key>tooltip</key>
275-
<string>Metatable for declaring table as an empty array for json encode</string>
275+
<string>Metatable for declaring table as an object for json encode.</string>
276276
<key>type</key>
277-
<string>{ [any]: any }</string>
277+
<string>{__jsonhint: string}</string>
278278
<key>value</key>
279-
<string>{}</string>
279+
<string>{__jsonhint = "object"}</string>
280280
</map>
281-
<key>lljson.null</key>
281+
<key>lljson.remove</key>
282282
<map>
283283
<key>tooltip</key>
284-
<string>A constant to pass for null to json encode</string>
284+
<string>A constant to return from a reviver/replacer replacer function to omit this item.</string>
285285
<key>type</key>
286286
<string>any</string>
287287
</map>
@@ -13104,6 +13104,15 @@ Returns true if result is non-zero.</string>
1310413104
<string>string</string>
1310513105
</map>
1310613106
</map>
13107+
<map>
13108+
<key>options</key>
13109+
<map>
13110+
<key>tooltip</key>
13111+
<string></string>
13112+
<key>type</key>
13113+
<string>LLJsonDecodeOptions?</string>
13114+
</map>
13115+
</map>
1310713116
</array>
1310813117
<key>energy</key>
1310913118
<real>10.0</real>
@@ -13127,6 +13136,15 @@ Returns true if result is non-zero.</string>
1312713136
<string>any</string>
1312813137
</map>
1312913138
</map>
13139+
<map>
13140+
<key>options</key>
13141+
<map>
13142+
<key>tooltip</key>
13143+
<string></string>
13144+
<key>type</key>
13145+
<string>LLJsonEncodeOptions?</string>
13146+
</map>
13147+
</map>
1313013148
</array>
1313113149
<key>energy</key>
1313213150
<real>10.0</real>
@@ -13150,6 +13168,15 @@ Returns true if result is non-zero.</string>
1315013168
<string>string</string>
1315113169
</map>
1315213170
</map>
13171+
<map>
13172+
<key>options</key>
13173+
<map>
13174+
<key>tooltip</key>
13175+
<string></string>
13176+
<key>type</key>
13177+
<string>LLJsonDecodeOptions?</string>
13178+
</map>
13179+
</map>
1315313180
</array>
1315413181
<key>energy</key>
1315513182
<real>10.0</real>
@@ -13174,12 +13201,12 @@ Returns true if result is non-zero.</string>
1317413201
</map>
1317513202
</map>
1317613203
<map>
13177-
<key>tight</key>
13204+
<key>options</key>
1317813205
<map>
1317913206
<key>tooltip</key>
1318013207
<string></string>
1318113208
<key>type</key>
13182-
<string>boolean?</string>
13209+
<string>LLJsonEncodeOptions?</string>
1318313210
</map>
1318413211
</map>
1318513212
</array>

generated/slua_selene.yml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4339,49 +4339,56 @@ globals:
43394339
The output is truncated at the first decoding error.
43404340
lljson.null:
43414341
property: read-only
4342-
description: A constant to pass for null to json encode
4343-
lljson.empty_array_mt:
4342+
description: A constant to pass for null to json encode.
4343+
lljson.remove:
43444344
property: read-only
4345-
type: table
4346-
description: Metatable for declaring table as an empty array for json encode
4345+
description: A constant to return from a reviver/replacer replacer function to
4346+
omit this item.
43474347
lljson.array_mt:
43484348
property: read-only
43494349
type: table
4350-
description: Metatable for declaring table as an array for json encode
4351-
lljson.empty_array:
4350+
description: Metatable for declaring table as an array for json encode.
4351+
lljson.object_mt:
43524352
property: read-only
4353-
description: A constant to pass for an empty array to json encode
4354-
lljson._NAME:
4353+
type: table
4354+
description: Metatable for declaring table as an object for json encode.
4355+
lljson.empty_array:
43554356
property: read-only
4356-
type: string
4357-
description: Name of the lljson library
4358-
lljson._VERSION:
4357+
type: table
4358+
description: A constant to pass for an empty array to json encode.
4359+
lljson.empty_object:
43594360
property: read-only
4360-
type: string
4361-
description: Version of the lljson library
4361+
type: table
4362+
description: A constant to pass for an empty object to json encode.
43624363
lljson.encode:
43634364
args:
43644365
- type: any
4366+
- type: table
4367+
required: false
43654368
must_use: true
43664369
description: Encodes a Lua value as JSON. Raises an error if value contains unsupported
43674370
types.
43684371
lljson.decode:
43694372
args:
43704373
- type: string
4374+
- type: any
4375+
required: false
43714376
must_use: true
43724377
description: Decodes a JSON string to a Lua value. Raises an error if JSON is
43734378
invalid.
43744379
lljson.slencode:
43754380
args:
43764381
- type: any
4377-
- type: bool
4382+
- type: table
43784383
required: false
43794384
must_use: true
43804385
description: Encodes a Lua value as JSON, preserving SL types. Use tight to encode
43814386
more compactly. Raises an error if value contains unsupported types.
43824387
lljson.sldecode:
43834388
args:
43844389
- type: string
4390+
- type: any
4391+
required: false
43854392
must_use: true
43864393
description: Decodes a JSON string to a Lua value, preserving SL types. Raises
43874394
an error if JSON is invalid.

0 commit comments

Comments
 (0)