lua-users home
lua-l archive

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



True, but there could be an assert function with a level that uses (level, assert_value, msg) as format. Would be useful to have such a function, I was similarly annoyed in the past about the lack of a level argument for asserts...

You can write that assert_level function yourself if you wish.
But I would be against its introduction in regular Lua sources, because it is incompatible with the current assert function and adds IMHO very little value.

You can either try hard to always put the current level to error() (and assert) function so that the buggy user source line appears in the error message.
I think this is impossible to achieve in the general case.
You could otherwise make sure that the _stack trace_ is reported when a user error occurs (and that your users know how to read the information).
Standard Lua interpreter outputs the stack trace on error, but this is not the case by default when you use lua_pcall and pcall functions.
However, it is not difficult to pass the debug.traceback function to the `int msgh` argument of lua_pcall, and to replace pcall with xpcall with suitable arguments.


--
-- Patrick Rapin
-- coauthor of "Le guide de Lua et ses applications", D-BookeR