Skip to content

Instantly share code, notes, and snippets.

@fur-q
Last active November 26, 2015 15:19
Show Gist options
  • Save fur-q/d435e571b5f1ed532649 to your computer and use it in GitHub Desktop.
Save fur-q/d435e571b5f1ed532649 to your computer and use it in GitHub Desktop.
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