A fast, easy to use, and configurable, INI serialiser and deserialiser for the Odin programming language.
package main
import ini "path/to/odin-ini"
import "core:fmt"
main :: proc() {
ini.Options.Rules.AllowNestedSections = true
ini.Options.Symbols.Comment = '#'
config := ini.read_from_file("config.ini")
defer ini.destroy_config(config)
ini.set(config, "example", "yes")
ini.get(config, "example") // "yes"
names := ini.add_section(config, "names")
ini.set(names, "Player1", "Dick Hunter")
ini.set(names, "Player2", "Mike Hunt")
s := ini.write_to_string(config)
fmt.println(s)
delete(s)
}
Note
More information about Odin ini including installation and usage can be found in the project's documentation.
The recommended way to install odin-ini
is to use git submodules. This way you can easily update to the latest version of the library.
First, create a new git repository for your project if you haven't already:
git init .
Next, create an external/
(or any other name) directory in the root of your project. This will hold all the external dependencies.
Then, add odin-ini
as a submodule:
git submodule add https://github.com/hrszpuk/odin-ini.git external/odin-ini
Finally, add the odin-ini
directory to your Odin project file:
package main
// Import the odin-ini package from path
import "external/odin-ini/"
main :: proc() {
// Follow the documentation to find out how to use the library
config := ini.read_from_file("config.ini");
ini.set(config, "count", "42")
ini.write_to_file(config);
ini.destroy_config(config);
}
package main
import ini "path/to/odin-ini"
import "core:fmt"
main :: proc() {
// Configure different ini options
ini.Options.Rules.AllowNestedSections = true
ini.Options.Symbols.Comment = '#'
// config := ini.new_config("config.ini")
config := ini.read_from_file("config.ini")
// Basic set and get keys
ini.set(config, "example", "yes")
ini.get(config, "example") // "yes"
ini.get_section(config, "section_name")
// Section called "names"
names := ini.add_section(config, "names")
ini.set(names, "Player1", "Dick Hunter")
ini.set(names, "Player2", "Mike Hunt")
// Nested section call "numbers" inside "names"
numbers := ini.add_section(names, "numbers")
ini.set(numbers, "one", "1")
ini.set(numbers, "two", "2")
// Convert the ini config into string (key=value, [section], etc)
s := ini.write_to_string(config)
fmt.println(s)
delete(s)
ini.destroy_config(config) // Delete everything
}
Coming soon...