lua-users home
lua-l archive

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

One possibility is to wrap a call to error():

function leave()
    error( "__LEAVE__" )

When pcall() returns with false, check the second return value for the
pre-defined "__LEAVE__" message.


> -----Original Message-----
> From: 
> [] On Behalf Of 
> Brett Kapilik
> Sent: Wednesday, October 20, 2004 2:49 PM
> To:
> 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