Skip to content

Instantly share code, notes, and snippets.

@nilium
Created July 20, 2009 23:45
Show Gist options
  • Save nilium/150993 to your computer and use it in GitHub Desktop.
Save nilium/150993 to your computer and use it in GitHub Desktop.
function chainfunc(...)
local chain={...}
return function(...)
local first = true
local a,b,c,d,e,f
for i,v in ipairs(chain) do
if first then
result = {v(...)}
first = false
else
result = {v(unpack(result))}
end
end
return unpack(result)
end
end
math.randomseed(os.time()); math.random()
print(
chainfunc(
-- Add 'ern' suffix if the name is a compass direction
function(v)
local vl = string.lower(v)
if vl == "west" or vl == "east" or vl == "south" or vl == "north" then
v = v.."ern"
end
return v, y
end,
-- Add a random street number
function(x)
local streetnum = math.random(80)
local lastchar = string.char( string.byte(streetnum, #tostring(streetnum)) )
if lastchar == "1" and (streetnum == 1 or streetnum > 11) then
streetnum = streetnum.."st"
elseif lastchar == "2" and (streetnum == 2 or streetnum > 12) then
streetnum = streetnum.."nd"
elseif lastchar == "3" and (streetnum == 3 or streetnum > 13) then
streetnum = streetnum.."rd"
else
streetnum = streetnum.."th"
end
return x.." "..streetnum, y
end,
-- Add a random street suffix
function(y)
local names = {" Street", " Boulevard", " Road", " Crossing", ""}
return(y..names[math.random(#names)]), x
end
)("East Hastings")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment