mirror of
https://github.com/bartbes/inifile.git
synced 2024-11-15 23:54:23 +00:00
Fix adding and removing of keys in inifile, fix typo
This commit is contained in:
parent
8bdf26e359
commit
649d4da453
@ -121,11 +121,15 @@ function inifile.save(name, t, backend)
|
|||||||
|
|
||||||
local function writevalue(section, key)
|
local function writevalue(section, key)
|
||||||
local value = section[key]
|
local value = section[key]
|
||||||
|
-- Discard if it doesn't exist (anymore)
|
||||||
|
if value == nil then return end
|
||||||
table.insert(contents, ("%s=%s"):format(key, tostring(value)))
|
table.insert(contents, ("%s=%s"):format(key, tostring(value)))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function writesection(section, order)
|
local function writesection(section, order)
|
||||||
local s = t[section]
|
local s = t[section]
|
||||||
|
-- Discard if it doesn't exist (anymore)
|
||||||
|
if not s then return end
|
||||||
table.insert(contents, ("[%s]"):format(section))
|
table.insert(contents, ("[%s]"):format(section))
|
||||||
|
|
||||||
-- Write our comments out again, sadly we have only achieved
|
-- Write our comments out again, sadly we have only achieved
|
||||||
@ -137,12 +141,15 @@ function inifile.save(name, t, backend)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Write the key-value pairs with optional order
|
-- Write the key-value pairs with optional order
|
||||||
|
local done = {}
|
||||||
if order then
|
if order then
|
||||||
for _, v in ipairs(order) do
|
for _, v in ipairs(order) do
|
||||||
|
done[v] = true
|
||||||
writevalue(s, v)
|
writevalue(s, v)
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
for i, _ in pairs(s) do
|
for i, _ in pairs(s) do
|
||||||
|
if not done[i] then
|
||||||
writevalue(s, i)
|
writevalue(s, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -152,12 +159,16 @@ function inifile.save(name, t, backend)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Write the sections, with optional order
|
-- Write the sections, with optional order
|
||||||
|
local done = {}
|
||||||
if sectionorder then
|
if sectionorder then
|
||||||
for _, v in ipairs(sectionorder) do
|
for _, v in ipairs(sectionorder) do
|
||||||
|
done[v.name] = true
|
||||||
writesection(v.name, v)
|
writesection(v.name, v)
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
for i, _ in pairs(contents) do
|
-- Write anything that wasn't ordered
|
||||||
|
for i, _ in pairs(t) do
|
||||||
|
if not done[i] then
|
||||||
writesection(i)
|
writesection(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user