[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Noob question -- On error, exit function and terminate script
- From: Lorenzo Donati <lorenzodonatibz@...>
- Date: Sat, 25 Jun 2011 21:01:57 +0200
On 25/06/2011 20.35, marbux wrote:
On Sat, Jun 25, 2011 at 7:12 AM, Rebel Neurofog<firstname.lastname@example.org> wrote:
assert () is the best in your case (more verbose)
Thank you, Rebel, and the others who responded; assert works for my use case.
BTW, I suggest that Reference Manual section 5.1 be amended to
indicate that assert and error will cause termination of the script
when their evaluations indicate an error condition.
This is not necessarily true. Citing from "error" entry in the manual:
"Terminates the last protected function called and returns message as
the error message."
If "error" is called inside a function called with pcall or xpcall, the
script doesn't terminate.
As for the relevance of that sentence: a script is nothing more than a
chunk (i.e. a function) loaded from a file, so if it is run in protected
mode, it doesn't terminate.
For example (untested code):
local chunk = assert( loadfile "script2.lua" )
pcall( chunk )
print "chunk broken, but I'm still alive!"
error "I'm broken!!!"
is currently not included in their respective documentation sections.