[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: <close> and os.exit()
- From: Sean Conner <sean@...>
- Date: Fri, 29 May 2020 16:57:45 -0400
It was thus said that the Great Phil Leblanc once stated:
> When os.exit() is called, by default the finalizer for <close>
> variables is not executed. If the second (optional) argument to
> os.exit() is true, then the Lua state is closed, and finalizers are
> executed.
>
> local x <close>
> ...
> os.exit(1) -- x finalizer is not called
> os.exit(1, true) -- x finalizer is called
>
> I suggest to change the default for the second exit() argument so that
> the default be to call finalizers upon exit.
The reason for the behavior is to remain compatible with Lua 5.1. The
calls:
os.exit(1)
os.exit(1,nil)
os.exit(1,false)
are the same, because nil and false are "falsy values" in Lua (all else is
true). I can see the reasoning behind making the finalizers always called
on exit(), but it will result in different behavior between Lua 5.1 (which
is still widely used) and 5.2+.
Besides, I think using 'true' to signify NOT to do something is, to me,
counterintuitive.
-spc