toml
TOML codec. See the formats overview for the shared codec shape and encoding rules common to every format.
Examples
Generate a config:
local rb = require("rootbeer")
rb.toml.write("~/.config/myapp/config.toml", {
app = {
name = "rootbeer",
workers = 4,
},
features = { "fast", "secure" },
})Read and patch:
local cfg = rb.toml.read("~/.cargo/config.toml")
cfg.build = cfg.build or {}
cfg.build.jobs = 8
rb.toml.write("~/.cargo/config.toml", cfg)Notes
- Arrays of scalars use inline syntax (
features = ["fast", "secure"]); arrays of tables use[[array]]syntax. - TOML datetimes are decoded as strings — bring your own date library if you need to manipulate them.
API
rootbeer.toml.decode(s)
Parses a TOML string into a Lua table. TOML datetimes are returned as strings (use a date library if you need richer types).
Parameters
sstringReturns
table — The decoded value.rootbeer.toml.encode(t)
Serializes a Lua table to a TOML string.
Parameters
ttableReturns
string — The TOML-encoded string (no trailing newline).rootbeer.toml.read(path)
Reads and decodes a TOML file. Equivalent to decode(slurp(path)). Path supports ~ expansion and is resolved against the script directory. This call is synchronous — the file must exist at plan time.
Parameters
pathstringReturns
table — The decoded value.rootbeer.toml.write(path, t)
Encodes a table and writes it to a file. Equivalent to rb.file(path, encode(t)). The write is deferred until the apply stage. A trailing newline is always added so the file is well-formed.
Parameters
pathstringttable