[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: assert with formatting
 
- From: Daurnimator <quae@...>
 
- Date: Fri, 13 Jul 2018 10:32:29 +1000
 
On 13 July 2018 at 10:11,  <tobias@justdreams.de> wrote:
> Quoting Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>> For that, you'll have to redefine assert to call error with the
>> correct stack level.
>
>
> Thank you, that's something I can work with. I looked at the source code and
> it
> seems dirty to patch it into luaB_assert()
Writing your own assert function is quite easy:
function assert(cond, ...)
    if cond then
        return cond, ...
    else
        local err = select("#", ...) == 0 and "assertion failed!" or ...
        error(err, 2)
    end
end
The second parameter to 'error' tells it to ignore the 'assert'
function when generating a stack trace.