Skip to content

Instantly share code, notes, and snippets.

@nefftd
Last active August 29, 2015 14:00
Show Gist options
  • Save nefftd/11382745 to your computer and use it in GitHub Desktop.
Save nefftd/11382745 to your computer and use it in GitHub Desktop.
-- depends on tostringall() https://gist.github.com/nefftd/11382819
-- see: line 15
do
local err_fmt = "bad argument #%d to '%s' (%s expected, got %s)"
local function checktypelist(t,a1,...)
if a1 then
return t == a1 or checktypelist(t,...)
end
end
function argcheck(val,argn,...)
local t = type(val)
if not checktypelist(t,...) then
local types = table.concat({tostringall(...)},'/')
local fname = debug.getinfo(2,'n').name or 'unknown'
argn = tonumber(argn) or 0
error(err_fmt:format(argn,fname,types,t),3)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment