Skip to content

Instantly share code, notes, and snippets.

View DaeZak's full-sized avatar

DaeZak

  • Georgia
View GitHub Profile
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 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]*)%]")
@DaeZak
DaeZak / puts-on-shades-unicode
Created February 24, 2017 20:06
Unicode emote of putting on sunglasses
(•_•)
( •_•)>⌐■-■
(⌐■_■)