mirror of
https://github.com/AntumMT/mod-wdata.git
synced 2024-11-19 22:13:45 +01:00
Add flag option "null_to_table" to convert null values to table in wdata.write
This commit is contained in:
parent
af22d136de
commit
3794faca1f
9
api.lua
9
api.lua
@ -58,6 +58,7 @@ end
|
|||||||
--
|
--
|
||||||
-- @table FlagsDef
|
-- @table FlagsDef
|
||||||
-- @tfield[opt] bool styled Outputs in a human-readable format if this is set (default: `true`).
|
-- @tfield[opt] bool styled Outputs in a human-readable format if this is set (default: `true`).
|
||||||
|
-- @tfield[opt] bool null_to_table "null" values will be converted to tables in output (default: `false`).
|
||||||
|
|
||||||
|
|
||||||
--- Writes to config file in world directory.
|
--- Writes to config file in world directory.
|
||||||
@ -97,6 +98,14 @@ function wdata.write(fname, data, flags)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if flags.null_to_table then
|
||||||
|
if flags.styled then
|
||||||
|
json_data = json_data:gsub(": null([,\n])", ": {}%1")
|
||||||
|
else
|
||||||
|
json_data = json_data:gsub(":null([,%]}])", ":{}%1")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return core.safe_file_write(fpath, json_data)
|
return core.safe_file_write(fpath, json_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
next
|
next
|
||||||
----
|
----
|
||||||
- changed wdata.write method to take table parameter "flags" instead of boolean "styled"
|
- changed wdata.write method to take table parameter "flags" instead of boolean "styled"
|
||||||
|
- added flag option "null_to_table" for wdata.write that converts null values to tables
|
||||||
|
|
||||||
|
|
||||||
v1.1
|
v1.1
|
||||||
|
Loading…
Reference in New Issue
Block a user