Last active
November 26, 2015 15:19
-
-
Save fur-q/d435e571b5f1ed532649 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 asr = {} | |
function asr.equal(a, b) return a == b end | |
function asr.error(fn, ...) local ok, out = pcall(fn, ...) return (not ok) and out end | |
function asr.match(a, b) return tostring(a):match(b) end | |
function asr.type(a, b) return type(a) == b end | |
local mt = {} | |
function mt.__index(t, k) | |
if not asr[k] then return end | |
return function(...) | |
local ok = asr[k](...) | |
if ok then | |
return ok | |
end | |
local args = {} | |
for i = 1, select('#', ...) do | |
args[i] = tostring(select(i, ...)) | |
end | |
error(string.format("assert.%s failed; args: %s", k, table.concat(args, ", ")), 2) | |
end | |
end | |
mt.__call = assert | |
return setmetatable({}, mt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment