[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Noob question -- On error, exit function and terminate script
- From: Rebel Neurofog <rebelneurofog@...>
- Date: Sat, 25 Jun 2011 21:00:21 +0400
> 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