Skip to content

Commit aebf820

Browse files
author
BirdeeHub
committed
docs(readme): readme
1 parent 0450f0e commit aebf820

1 file changed

Lines changed: 35 additions & 17 deletions

File tree

README.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,27 +98,45 @@ tomlua.opts.fancy_dates = true
9898

9999
local data, err = tomlua.decode(some_string)
100100

101-
local data, err = tomlua.decode(some_string, {
102-
some = "defaults",
103-
can_go = "here",
101+
local defaults = {
104102
tables_and_arrays = "defined in headings will extend the associated value",
105-
and_inline = "values from the toml will override it instead",
106-
})
103+
and_inline = "values from the toml will override it instead", -- NOTE: <-- subject to change?
104+
example = {
105+
if_defined = "as a heading",
106+
the_values_here = "will be recursively updated",
107+
},
108+
example2 = {
109+
"if defined as a heading",
110+
"it will append",
111+
},
112+
}
113+
local data, err = tomlua.decode(some_string, defaults)
107114

108-
-- encode always accepts fancy dates, never outputs fancy tables, and is unaffected by all opts
109-
-- instead you may customize dates by replacing them with tomlua date types
110-
-- and you may decide to make some strings multiline with tomlua.str_2_mul
111-
-- and you may make arrays appear as tables, or empty tables appear as arrays,
112-
-- local empty_toml_array = setmetatable({}, {
113-
-- toml_type = "ARRAY"
114-
-- })
115-
-- local a_toml_table = setmetatable({ "a", "table", "with", "integer", "keys" }, {
116-
-- toml_type = tomlua.types.TABLE -- it also accepts the numbers
117-
-- })
118-
-- you may do the same with the ARRAY_INLINE and TABLE_INLINE types to force them to display inline
119-
-- there are some circumstances where this doesn't make sense, however. In that case, set it 1 level higher.
120115
local str, err = tomlua.encode(some_table)
116+
```
117+
118+
119+
encode always accepts fancy dates, never outputs fancy tables, and is unaffected by all opts
120+
121+
Instead you may customize the values themselves.
122+
123+
You may create date objects, and you may decide to make some strings multiline with tomlua.str_2_mul
124+
125+
You may make arrays appear as tables, or empty tables appear as arrays.
121126

127+
```lua
128+
local empty_toml_array = setmetatable({}, {
129+
toml_type = "ARRAY"
130+
})
131+
local a_toml_table = setmetatable({ "a", "table", "with", "integer", "keys" }, {
132+
toml_type = tomlua.types.TABLE -- it also accepts the numbers
133+
})
134+
```
135+
136+
you may do the same with the ARRAY_INLINE and TABLE_INLINE types to force them to display inline
137+
there are some circumstances where this doesn't make sense, however. In that case, set it 1 level higher.
138+
139+
```lua
122140
tomlua.types = {
123141
UNTYPED, -- 0 -- Untyped TOML Item
124142
STRING, -- 1 -- lua string

0 commit comments

Comments
 (0)