Created
July 26, 2014 05:11
-
-
Save nefftd/5b22f90918dd70c1b13e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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