Skip to content

Instantly share code, notes, and snippets.

@pingbird
Created March 14, 2014 15:20
Show Gist options
  • Select an option

  • Save pingbird/9549828 to your computer and use it in GitHub Desktop.

Select an option

Save pingbird/9549828 to your computer and use it in GitHub Desktop.
WIP config parser
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