You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-20Lines changed: 10 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,8 +14,8 @@ It is not intended to replace packages like [toml\_edit](https://github.com/nvim
14
14
* Fast parsing of TOML files into Lua tables.
15
15
* Emits TOML from Lua tables (also quickly).
16
16
* Compatible with Lua 5.1+.
17
-
* Supports embedding in Lua C modules or Nix packaging.
18
17
* Some advanced TOML compliance features are optional (`fancy_dates`, etc.).
18
+
* Allows you to read directly into an existing lua table of defaults. This cuts out the step of merging them yourself, making it even more performant and easier to use!
19
19
20
20
## Limitations
21
21
@@ -27,8 +27,8 @@ It is not intended to replace packages like [toml\_edit](https://github.com/nvim
27
27
28
28
Basic benchmarking shows promising results:
29
29
30
-
* Slightly slower than `cjson` (1.5x), despite parsing TOML instead of JSON.
31
-
* Around **10x faster** than `toml_edit` for parsing.
30
+
* Slightly slower than `cjson` (2x longer), despite parsing TOML instead of JSON.
31
+
* Around 7x faster than `toml_edit` for parsing (not accounting for the added ability to read directly into an existing lua table).
32
32
33
33
## Installation
34
34
@@ -98,6 +98,13 @@ tomlua.opts.fancy_dates = true
98
98
99
99
localdata, err=tomlua.decode(some_string)
100
100
101
+
localdata, err=tomlua.decode(some_string, {
102
+
some="defaults",
103
+
can_go="here",
104
+
and="tables and arrays defined in headings will extend the associated value",
105
+
and_inline="values from the toml will override it instead",
106
+
})
107
+
101
108
-- encode always accepts fancy dates, never outputs fancy tables, and is unaffected by all opts
102
109
-- instead you may customize dates by replacing them with tomlua date types
103
110
-- and you may decide to make some strings multiline with tomlua.str_2_mul
@@ -187,20 +194,3 @@ As a result of that, editing existing toml files, or emitting them at all, only
187
194
This means that it makes a lot of sense to use a simple but fast parser to parse config files on startup.
188
195
189
196
And then later you can use one which is better for editing but is slower when making things like a settings page which may edit the file.
190
-
191
-
Randomly selected benchmark run of 100_000 parses of the example toml file:
192
-
193
-
```
194
-
-- tomlua
195
-
Parsed TOML 100000 times in 2.142739 seconds, avg. 46669.239697 iterations per second, avg. 21.43 µs/iteration
196
-
-- cjson, parsing output of tomlua decode
197
-
Parsed JSON 100000 times in 1.284222 seconds, avg. 77868.156752 iterations per second, avg. 12.84 µs/iteration
0 commit comments