Created
April 1, 2014 14:02
-
-
Save etandel/9914600 to your computer and use it in GitHub Desktop.
Beatifies Holy Lua Scripts.
This file contains 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
#!/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