-
Notifications
You must be signed in to change notification settings - Fork 9
/
lip.lua
40 lines (36 loc) · 998 Bytes
/
lip.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local LIP = {};
--- Returns a table containing all the data from the INI file.
--@param fileName The name of the INI file to parse. [string]
--@return The table containing all data from the INI file. [table]
function LIP.load(fileName)
local file, error = io.open(fileName, 'r')
if (error ~= nil) then
return nil
end
local data = {};
local section;
for line in file:lines() do
local tempSection = line:match('^%[([^%[%]]+)%]$');
if(tempSection)then
section = tonumber(tempSection) and tonumber(tempSection) or tempSection;
data[section] = data[section] or {};
end
local param, value = line:match('^([%w|_]+)%s-=%s-(.+)$');
if(param and value ~= nil)then
if(tonumber(value))then
value = tonumber(value);
elseif(value == 'true')then
value = true;
elseif(value == 'false')then
value = false;
end
if(tonumber(param))then
param = tonumber(param);
end
data[section][param] = value;
end
end
file:close();
return data;
end
return LIP;