Skip to content

Instantly share code, notes, and snippets.

@nefftd
Created July 26, 2014 05:11
Show Gist options
  • Save nefftd/5b22f90918dd70c1b13e to your computer and use it in GitHub Desktop.
Save nefftd/5b22f90918dd70c1b13e to your computer and use it in GitHub Desktop.
do
local err_fmt = "bad argument #%s to '%s' (%s expected, got %s)"
local function checktypelist(t,a1,...)
if a1 then
return t == a1 or checktypelist(t,...)
end
end
function mod:argcheck(val,argn,...)
if not checktypelist(type(val),...) then
local name = debugstack(2,1,0):match("in function `([^']+)'") or '?'
local types = ('/'):join(tostringall(...))
argn = tonumber(argn) or '?'
error(err_fmt:format(argn,name,types,type(val)),3)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment