This is a simple INI file parser with Lua, allowing modification of .ini from Lua codes. Supports comments, keeping line orders, avoiding empty line cutting, and more.
- Copy
ini_parser.lua
script from this repository and paste it anywhere in your project directory. - Get functions from
ini_parser.lua
via require (EX:local ini_parser = require('ini_parser")
- That's it!
- ini_parser.read(fileName) : Returns a table containing all the values from the file.
- ini_parser.write(fileName, data) : Saves the data into the specified file.
local ini_parser = require('ini_parser')
-- Create data to write to the INI file
local data = {
Settings = {
resolution = "1920x1080",
fullscreen = true
},
User = {
username = "player1",
highscore = 5000
}
}
-- Write the data to the INI file
ini_parser.write('config.ini', data)
Result would look like this:
[Settings]
resolution=1920x1080
fullscreen=true
[User]
username=player1
highscore=5000
local ini_parser = require('ini_parser')
local data = ini_parser.read('config.ini')
--[[ This returns:
local data = {
Settings = {
resolution = "1920x1080",
fullscreen = true
},
User = {
username = "player1",
highscore = 5000
}
}
]]