Skip to content

Instantly share code, notes, and snippets.

@Deco
Created March 5, 2012 17:15
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 Deco/1979549 to your computer and use it in GitHub Desktop.
Save Deco/1979549 to your computer and use it in GitHub Desktop.
Ponies!
function Fluttershy(f, ...)
local decl = {...}
return function(...)
local arg = {...}
for arg_i = 1, math.ceil(#decl/2) do
if type(arg[arg_i]) ~= decl[arg_i*2-1] then
arg[arg_i] = decl[arg_i*2]
end
end
return f(unpack(arg))
end
end
x = Fluttershy(print,
"string", "not provided!",
"number", -9999,
"table", {}
)
print(x(1, 333))
function Assertershy(f, ...)
local decl = {...}
return function(...)
local arg = {...}
for arg_i = 1, #arg do
assert(type(arg[arg_i]) == decl[arg_i], "no")
end
return f(unpack(arg))
end
end
x = Assertershy(print,
"string",
"number",
"table"
)
print(x(1, 333, {}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment