lua-users home
lua-l archive

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


On 2 July 2014 08:24, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> Unfortunately, it is not possible with assert, you *must* pass a string.
> I think it can be great to also have assert working like error so the

This is supported in Lua 5.3.0 (work3).

For Lua 5.2, you can simply redefine assert:

function assert(cond,...)
        if cond then
                return cond,...
        else
                error(...)
        end
end

This is how assert is implemented in 5.3.


The vararg should not be passed through to error (it takes `level` as 2nd parameter)
This should be correct:

function assert(cond,err,...)
        if cond then
                return cond, err, ...
        else
                error(err, 2)
        end
end