Skip to content

Instantly share code, notes, and snippets.

@x4fx77x4f
Last active November 20, 2020 19:08
Show Gist options
  • Save x4fx77x4f/9246e07bbf3ea2aa3e43919cd6e62bcf to your computer and use it in GitHub Desktop.
Save x4fx77x4f/9246e07bbf3ea2aa3e43919cd6e62bcf to your computer and use it in GitHub Desktop.
Preprocessor and minifier for Quake/Source Engine .cfg files
#!/usr/bin/env luajit
local input = arg[1] and io.open(arg[1], 'r') or io.stdin
local output = arg[2] and io.open(arg[2], 'w+') or io.stdout
local inbrace = false
local firstbrace = false
for line in input:lines() do
if line:find('^[ \t]*//') or line == '' then
-- skip
elseif inbrace then
local o = line:find('}')
if o then
output:write('"')
output:write(line:sub(o+1))
output:write('\n')
inbrace = false
else
if not firstbrace then
output:write(';')
end
line = line:gsub('^[ \t]*', '')
output:write(line)
firstbrace = false
end
else
local o = line:find('{')
if o then
output:write(line:sub(1, o-1))
output:write('"')
inbrace = true
firstbrace = true
else
output:write(line)
output:write('\n')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment