[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: assert with formatting
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 13 Jul 2018 10:52:39 +0200
2018-07-13 2:32 GMT+02:00 Daurnimator <email@example.com>:
> On 13 July 2018 at 10:11, <firstname.lastname@example.org> wrote:
>> Quoting Luiz Henrique de Figueiredo <email@example.com>:
>>> 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
>> seems dirty to patch it into luaB_assert()
> Writing your own assert function is quite easy:
> function assert(cond, ...)
> if cond then
> return cond, ...
> local err = select("#", ...) == 0 and "assertion failed!" or ...
> error(err, 2)
> The second parameter to 'error' tells it to ignore the 'assert'
> function when generating a stack trace.
It does not ignore the 'assert' function, it just changes the source
code reference at the start of the message. The line number in
'assert' still appears in the traceback.