Created
March 14, 2014 15:20
-
-
Save pingbird/9549828 to your computer and use it in GitHub Desktop.
WIP config parser
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 lfs=require("lfs") | |
| local ids={} | |
| local base=[[C:\dir\to\config\folder]] | |
| local bti={ | |
| "block", | |
| "blocks", | |
| "item", | |
| "items", | |
| '"blocks and item ids"', -- CCLights | |
| } | |
| for fn in lfs.dir(base) do | |
| if fn:sub(-4,-1)==".cfg" then | |
| local file=io.open(base..fn,"r") | |
| local contents=file:read("*a") | |
| file:close() | |
| local found=false | |
| for k,v in pairs(bti) do | |
| for dat in contents:gmatch(v.." {(.-)}") do | |
| for name,id in dat:gmatch("I:([^=]+)=(%d+)") do | |
| found=true | |
| ids[name]=tonumber(id) | |
| end | |
| end | |
| end | |
| if not found then | |
| print("no ids in "..fn) | |
| end | |
| end | |
| end | |
| local used={} | |
| for k,v in pairs(ids) do | |
| local t=used[v] or {} | |
| table.insert(t,k) | |
| used[v]=t | |
| end | |
| for k,v in pairs(used) do | |
| for n,l in pairs(v) do | |
| print((#v>1 and "CONFLICT: " or "")..k..":"..l) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment