lua-users home
lua-l archive

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


It was thus said that the Great Steve Litt once stated:
> On Monday 07 March 2011 05:02:16 Shmuel Zeigerman wrote:
> > On 07/03/2011 11:40, Gilles Ganault wrote:
> > > I need to exit a script in case the user forgot to pass a parameter,
> > > and noticed that return works in the "if" block but doesn't when used
> > > in the main loop:  [snip]
> > 
> > Instead of just `return', you can always say:
> >    do return end
> > and that will return from the script.
> 
> I didn't know that. I've always just used os.exit().

  Both do the job, but os.exit() will cause the process to end immediately
without the garbage collector doing a final clean up.  I found this out the
hard way when I had some code that would flush a file and close it when the
object was garbage collected, but calling os.exit() would leave the file in
an inconsistent state.  Doing a 'return' from the script would cause the GC
to kick in.

  -spc (just an FYI ... )