-
-
Save Fingercomp/3975221042e4e16c83d7a5f6fceed0d1 to your computer and use it in GitHub Desktop.
This file contains 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
local checkArg = checkArg or function(pos, value, ...) | |
local exp = {...} | |
for _, tp in pairs(exp) do | |
if type(value) == tp then | |
return | |
end | |
end | |
if #exp == 1 then | |
exp = exp[1] | |
elseif #exp == 2 then | |
exp = table.concat(exp, " or ") | |
elseif #exp > 2 then | |
exp = table.concat(exp, ", ", 1, #exp - 1) .. ", or " .. exp[#exp] | |
end | |
error("bad argument #" .. pos .. ": " .. exp .. " expected, got " .. type(value)) | |
end | |
return function(class, name, func, doc) | |
checkArg(1, class, "table") | |
checkArg(2, name, "string") | |
checkArg(3, func, "function") | |
checkArg(4, doc, "string", "nil") | |
local method = setmetatable({},{ | |
__call = function(self, ...) | |
return func(...) | |
end, | |
__tostring = function(self) | |
return doc | |
end, | |
__index = method | |
}) | |
class[name] = method | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment