mirror of
https://github.com/bartbes/inifile.git
synced 2024-11-15 23:54:23 +00:00
Detect writing invalid sections
And display a proper error, instead of some random pairs-error
This commit is contained in:
parent
274bb1e0ce
commit
2acf400942
10
inifile.lua
10
inifile.lua
@ -140,12 +140,22 @@ function inifile.save(name, t, backend)
|
||||
table.insert(contents, ("%s=%s"):format(key, tostring(value)))
|
||||
end
|
||||
|
||||
local function tableLike(value)
|
||||
local function index()
|
||||
return value[1]
|
||||
end
|
||||
|
||||
return pcall(index) and pcall(next, value)
|
||||
end
|
||||
|
||||
local function writesection(section, order)
|
||||
local s = t[section]
|
||||
-- Discard if it doesn't exist (anymore)
|
||||
if not s then return end
|
||||
table.insert(contents, ("[%s]"):format(section))
|
||||
|
||||
assert(tableLike(s), ("Invalid section %s: not table-like"):format(section))
|
||||
|
||||
-- Write our comments out again, sadly we have only achieved
|
||||
-- section-accuracy so far
|
||||
if comments and comments[section] then
|
||||
|
Loading…
Reference in New Issue
Block a user