lua-users home
lua-l archive

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


Brett Kapilik wrote:
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.

I use return for this.
Note that return must be the last instruction of a block, so you have to write something like:

print"One"
do return end
print"Two"

Of course, most of the time you do a conditional break, so it would like more natural:

print"One"
if condition do return end
print"Two"

Note you can also call os.exit() but it is quite more brutal...

--
Philippe Lhoste
--  (near) Paris -- France
--  Professional programmer and amateur artist
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --