lua-users home
lua-l archive

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


Consider the following simple executable Lua script:

   #!/usr/bin/env lua5.3

   if #arg ~= 2 then
      print( arg[ 0 ] .. " : two parameters expected" )
      return
      end

   -- continue normal processing with two parameters
   ...
   ...

My question is about the use of 'return' to halt the script.

Is this totally valid?  Yes, it seems to work fine in practice,
but I have not seen any explicit confirmation or examples of its use
in either the Lua Reference Manual or Pil4 or elsewhere.

I think it *should* be valid, since the script contents forms a chunk,
which is treated as an (anonymous) function, and the 'return' from
inside this function should be fine.  Am I correct?

The alternative is, of course, to use 'os.exit( )' -- but in the above
context, does using 'return' basically achieve the same effect?

Thanks for any wisdom that you can impart!

-- Joseph

------------------------------------------------------------------------
Joseph Manning / Computer Science / UCC Cork Ireland / manning@cs.ucc.ie
------------------------------------------------------------------------