Replace "styled" parameter with "flags" in wdata.write

This commit is contained in:
Jordan Irwin 2021-08-28 18:51:13 -07:00
parent 9ae5b8e3ac
commit af22d136de
2 changed files with 26 additions and 4 deletions

24
api.lua

@ -54,17 +54,33 @@ function wdata.read(fname)
end end
--- Flags definition.
--
-- @table FlagsDef
-- @tfield[opt] bool styled Outputs in a human-readable format if this is set (default: `true`).
--- Writes to config file in world directory. --- Writes to config file in world directory.
-- --
-- @function wdata.write -- @function wdata.write
-- @tparam string fname Base filename with optional directory structure (e.g. "my_mod/my_config"). -- @tparam string fname Base filename with optional directory structure (e.g. "my_mod/my_config").
-- @tparam table data Table data to be written to config file. -- @tparam table data Table data to be written to config file.
-- @tparam[opt] bool styled Outputs in a human-readable format if this is set (default: `true`). -- @tparam[opt] FlagsDef flags
-- @treturn bool `true` if succeeded, `false` if not. -- @treturn bool `true` if succeeded, `false` if not.
function wdata.write(fname, data, styled) function wdata.write(fname, data, flags)
styled = styled ~= false -- backward compat
if type(flags) == "boolean" then
wdata.log("warning", "wdata.write: \"styled\" parameter deprecated, use \"flags\"")
flags = {styled=flags}
end
local json_data = core.write_json(data, styled) if type(flags) ~= "table" then
flags = {}
end
flags.styled = flags.styled ~= false
local json_data = core.write_json(data, flags.styled)
if not json_data then if not json_data then
wdata.log("error", "cannot convert data to json format") wdata.log("error", "cannot convert data to json format")
return false return false

@ -1,8 +1,14 @@
next
----
- changed wdata.write method to take table parameter "flags" instead of boolean "styled"
v1.1 v1.1
---- ----
- changed "error" message to "warning" when file not found for reading - changed "error" message to "warning" when file not found for reading
v1.0 v1.0
---- ----
- initial release - initial release