Skip to content

Instantly share code, notes, and snippets.

@etandel
Created April 1, 2014 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etandel/9914600 to your computer and use it in GitHub Desktop.
Save etandel/9914600 to your computer and use it in GitHub Desktop.
Beatifies Holy Lua Scripts.
#!/usr/bin/env lua
--[[
Example use:
$ ./beatify.lua beatify.lua
Saint Beatify, blessed be thy exit()!
--]]
function exit()
io.stderr:write("Error: A Holy Script must be provided.\n")
os.exit(1)
end
if #arg < 1 then
exit()
end
local script = arg[1]
local holy_name = script:match('(.+)%.lua')
if not holy_name then
exit()
end
local holy_name = holy_name:sub(1,1):upper() .. holy_name:sub(2)
local f = io.open(script, 'r')
if f then
local funcs = {}
local code = f:read('*a')
for fname in code:gmatch('function ([%w_%.]+)%s*%(') do
funcs[#funcs+1] = fname
end
if #funcs > 0 then
math.randomseed(os.time())
local fname = funcs[math.random(1, #funcs)]
io.write("Saint "..holy_name..", blessed be thy "..fname.."()!\n")
else
io.write("Blessed be Saint "..holy_name.."!\n")
end
f:close()
else
io.write("Blessed be Saint "..holy_name.."!\n")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment