1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-26 18:21:04 +00:00

Improve minetest.parse_json

Let modders handle parsing errors, get rid of two unnecessary copies.
This commit is contained in:
Lars Mueller 2024-10-12 23:24:47 +02:00 committed by Lars Müller
parent c7938ce81c
commit 4c419c4020
3 changed files with 48 additions and 35 deletions

View file

@ -7404,11 +7404,13 @@ Misc.
* Gets the internal content ID of `name`
* `minetest.get_name_from_content_id(content_id)`: returns a string
* Gets the name of the content with that content ID
* `minetest.parse_json(string[, nullvalue])`: returns something
* `minetest.parse_json(string[, nullvalue, return_error])`: returns something
* Convert a string containing JSON data into the Lua equivalent
* `nullvalue`: returned in place of the JSON null; defaults to `nil`
* On success returns a table, a string, a number, a boolean or `nullvalue`
* On failure outputs an error message and returns `nil`
* On failure: If `return_error` is not set or is `false`,
outputs an error message and returns `nil`.
Otherwise returns `nil, err` (error message).
* Example: `parse_json("[10, {\"a\":false}]")`, returns `{10, {a = false}}`
* `minetest.write_json(data[, styled])`: returns a string or `nil` and an error
message.