lua-users home
lua-l archive

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


Am 02.01.2013 21:00, schrieb Thijs Schreijer:

Another caveat is that some functions in os and many functions in io
return nil,msg,errno in case of error, and this would mess with the level
argument ...

That is indeed a nasty one. But still very annoying that there is no level on an assert call. Any ideas on how to add such a thing without breaking anything?

AFAIK there is no function (in the standard library) returning more than three values in the error case, so `assert( ok, msg, _, lvl )` probably would work. But I believe the current protocol is: nil, error_msg, + whatever_is_useful, so it will likely break for some third party code. You could always add separate functions for different stack levels (assert, assert1, assert2, assert3, ...). My favorite would be a func-table with a memoizing __index: assert( bla() ), assert[2]( blub() ) ), etc., but this will probably break some unit testing frameworks (if they replace assert themselves).


Thijs


Philipp