lua-users home
lua-l archive

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


Thanks Kevin this is what I ended up going with.  It seems to work well.  Thanks for all of the other suggestions and replies.  It was all very helpful.

- Brett

> -----Original Message-----
> From: Kevin Baca [mailto:lualist@aidiastudios.com]
> Sent: Wednesday, October 20, 2004 3:59 PM
> To: 'Lua list'
> Subject: RE: Exit chunk
> 
> 
> One possibility is to wrap a call to error():
> 
> function leave()
>     error( "__LEAVE__" )
> end
> 
> When pcall() returns with false, check the second return value for the
> pre-defined "__LEAVE__" message.
> 
> -Kevin
> 
> 
> > -----Original Message-----
> > From: lua-bounces@bazar2.conectiva.com.br 
> > [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of 
> > Brett Kapilik
> > Sent: Wednesday, October 20, 2004 2:49 PM
> > To: lua@bazar2.conectiva.com.br
> > Subject: Exit chunk
> > 
> > 
> > Hi,
> > 
> > I know that this has been addressed before, but I can't find 
> > it for the life of me.  My question is:
> > 
> > Is there an integrated way (or even a hack) to halt the 
> > execution of a Lua chunk.  What I would like is something like:
> > 
> > print ("hello");
> > breakfromscript;
> > print ("world");
> > 
> > would produce:
> > 
> > hello
> > 
> > That is, the fictional "breakfromscript" call would stop 
> > excution of the current script (from pcall).  Kind of like 
> > doing a return from a function.
> > 
> > This would be really helpful as a way to short circuit script 
> > executions in lengthy scripts.  I know that there are all 
> > sorts of "good" ways to do this like using if.. else and 
> > using functions, but it wouldbe helpful to our customers if 
> > there was a way to just tell the Lua engine to simply stop 
> > executing the current script chunk.
> > 
> > I am even willing to put a small hack into the Lua engine 
> > source code if one exists.
> > 
> > Thanks!
> > 
> > - Brett
> > 
> 
>