I made a simple ini parsing/dumping function. load_ini() converts an ini string to a table, and dump_ini() converts a lua table to an ini string.
This could be useful for projects that have a configuration file. Using an ini might be better for user configs since ini supports comments.
The ini format is simple. Section headings are marked with [section] and items are stored as key=value. Subsections are separated with a dot. Inline comments are not supported, but comments at the start of the line are.
Strings don't have to be quoted, but you should quote them.
Example:
[heading] a=1 b=2 [heading.sub] c="hello" d="world" [heading.array] 1=4 2=5 3=6 |
This will convert to:
{
heading = {
a = 1,
b = 2,
sub = {
c = "hello",
d = "world"
},
array = { 4, 5, 6 }
}
} |
With the way I wrote it, it can handle anything that can be parsed with unpod(). This may be useful for writing some things (such as arrays) more compactly. The following is equivalent to the above example:
[heading]
a=1
b=2
sub={c="hello",d="world"}
array={4,5,6} |
Changelog
2025-04-02:
- Allow subheadings to be numbers, providing a different way of writing arrays, and fixing an inconsistency with dump/load
[array.1] some=value [array.2] other=value |
Code under the cut
https://gist.github.com/Rayquaza01/e2cedb3ab53d166fdcd2c1a9cc950b1e
[Please log in to post a comment]




