function ini_read(ini_file, sec, ent, def_val) section = { } sec_count = 0 if (io.open(ini_file) ~= nil) then for line in io.lines(ini_file) do l = string.gsub(line, " ", "") c = string.byte(l, 1) if (c == 91) then pos = string.find(l, "]") if (pos ~= nil) then sectionname = string.sub(l, 2, pos-1) sec_count = sec_count + 1 section[sec_count] = { } section[sec_count].name = sectionname section[sec_count].entry_count = 0 end elseif (sec_count > 0) then pos = string.find(l, "=") if (pos ~= nil) then sub1 = string.sub(l, 1, pos-1) sub2 = string.sub(l, pos+1) if (section[sec_count].entry_count > 0) then section[sec_count].entry_count = section[sec_count].entry_count + 1 entry_count = section[sec_count].entry_count section[sec_count].entry[entry_count] = { } section[sec_count].entry[entry_count].name = sub1 section[sec_count].entry[entry_count].value = sub2 else section[sec_count].entry_count = section[sec_count].entry_count + 1 entry_count = section[sec_count].entry_count section[sec_count].entry = { } section[sec_count].entry[entry_count] = { } section[sec_count].entry[entry_count].name = sub1 section[sec_count].entry[entry_count].value = sub2 end end end end end for i = 1, sec_count, 1 do if (sec == section[i].name) then for j=1, section[i].entry_count, 1 do if (ent == section[i].entry[j].name) then if (section[i].entry[j].value ~= "") then result = section[i].entry[j].value if (result == "false") then return false elseif (result == "true") then return true elseif (tonumber(result) ~= nil) then return tonumber(result) else return result end end end end end end return def_val end