lua-users home
lua-l archive

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


2018-07-13 2:32 GMT+02:00 Daurnimator <quae@daurnimator.com>:
> 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.

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.