[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: <close> and os.exit()
- From: Phil Leblanc <philanc@...>
- Date: Fri, 29 May 2020 17:30:26 +0000
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.
In special cases where the intent is ro _not_ call the finalizers, the
optional argument to exit should be set to true.
So the os.exit signature would be: os.exit ([code [, noclose]])
and the behavior would be
os.exit(1) -- finalizers are called (the default)
os.exit(1, true) -- finalizers are not called
In a way, it is the same logic as in C:
exit(1);
// the default behavior is to call the atexit()-registered functions.
_exit();
// In the special cases where atexit()-registered functions should
// not be called, _exit() should be used instead of exit
Phil