lua-users home
lua-l archive

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

Brett Kapilik wrote:

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");
print ("world");

would produce:


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:

do return end

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

if condition do return end

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

Philippe Lhoste
--  (near) Paris -- France
--  Professional programmer and amateur artist
--  --  --  --  --  --  --  --  --  --  --  --