mirror of
https://github.com/AntumMT/mod-wdata.git
synced 2024-11-19 22:13:45 +01:00
Replace "styled" parameter with "flags" in wdata.write
This commit is contained in:
parent
9ae5b8e3ac
commit
af22d136de
24
api.lua
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
|
||||||
|
Loading…
Reference in New Issue
Block a user