lua-users home
lua-l archive

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


> do we have simple ASSERT like thing to do this automatic?
> just like macro or other thing...

Actually I would be glad if assert () would do this:
assert (bar ~= "", function () return "Error: "..some_complex_call () end)

But it doesn't: it only takes a string as a second argument. Even in Lua 5.2.
Sounds like a good proposal...

But for now it can only be emulated like that (as far as I know):

function assert2 (expr, message, ...)
   if expr then
      return expr, message, ...
   end
   if type (message) == "function" then
      return assert (expr, message (), ...)
   end
   return assert (expr, message, ...)
end