lua-users home
lua-l archive

Re: using 'return' to halt an executable Lua script

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


It was thus said that the Great Andrew Gierth once stated:
> >>>>> "Joseph" == Joseph Manning <manning@cs.ucc.ie> writes:
> 
> Joseph> The alternative is, of course, to use 'os.exit( )' -- but in
> Joseph> the above context, does using 'return' basically achieve the
> Joseph> same effect?
> 
> os.exit() doesn't close the Lua state before exiting, whereas returning
> from the invoked chunk does.
 An optional parameter to os.exit() was added to Lua 5.2 to indicate
closing of the Lua state. 
> $ lua53 -e 't = setmetatable({},{__gc=function() print "foo" end})'
> foo
> $
> 
> $ lua53 -e 't = setmetatable({},{__gc=function() print "foo" end}) os.exit(0)'
> $
$ lua-53 -e 't = setmetatable({},{__gc=function() print "foo" end}) os.exit(0,true)'
true
$
 -spc 

AltStyle によって変換されたページ (->オリジナル) /