This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local iniparse = {} | |
local trim = function(str) | |
return string.gsub(str, "^%s*(.-)%s*$", "%1") | |
end | |
local strip_comments = function(str) | |
return string.gsub(str, "^(.-)%s*([;#].*)$", "%1") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[==[ | |
This lib provides two functions: | |
* load_file(file) -- parses an ini file and returns a table | |
* parse(data) -- parses string data in ini format and returns a table | |
A few notes: iniparse will allow ; and # style comments, it does not allow duplicate sections and it will overwrite | |
duplicate keys/values with the last given key/value pair. | |
--]==] | |
local c={}local d=function(f)return string.gsub(f,"^%s*(.-)%s*$","%1")end local e=function(f)return string.gsub(f,"^(.-)%s*([;#].*)$","%1")end c.config=function(f)c.opts={trim=f.trim==nil and true or f.trim,lc=f.lc==nil and true or f.lc}end c.load_file=function(f)assert(type(f)=='string','load_file given non-string arg')local g=assert(io.open(f,'r'),'Error opening'..f)c.parse(g:read('*all'))end c.parse=function(f)assert(type(f)=='string','parse given non-string arg')local g={}local h=nil for i in f:gmatch("([^\n]*)\r?\n")do local j=c.opts.trim and d(i)or i j=c.opts.lc and j:lower()or j j=e(j)if j:len()>0 then local k=string.match(j,"^%[([%w%s%p]*)%]") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(•_•) | |
( •_•)>⌐■-■ | |
(⌐■_■) |