lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> function assertc(condn,fun)
>     if not condn then assert(false,fn()) end
> end

Here's an assert on esteroids that can be used to avoid concatenations
for instance:

do
	local old_assert=assert
	function assert(cond,what,...)
		if cond then
			return what,...
		else
			if type(what)=="function" then
				old_assert(cond,what())
			elseif type(what)=="string" then
				if ...==nil then
					old_assert(cond,what)
				else
					old_assert(cond,what:format(...))
				end
			end
		end
	end
end