lua-users home
lua-l archive

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


On Sat, May 30, 2020 at 6:52 PM Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>
> [...] so there is no need to waste time clearing everything manually
> when the script ends. Moreover, closing a state also frees all its
> memory, which is another dubious (and often large) expense.  So,
> the default was to just finish the program and let the OS do all the
> cleaning.

If closing the state is "another dubious (and often large) expense",
and if os.exit() by default ignores the to-be-closed varianbles, then
it would be nice to have a way to exit from any point and call all
finalizers (equivalent to returning from the main program).

An objective is to be able to implement an equivalent to C atexit() in pure Lua.

If closing the state or not makes a real difference, maybe exit()
second parameter could be used to choose between:
   - "exiit and ignore finalizers"  -- would be the default with
current 5.4 approach
          -- (equivalent to C _exit() )
   - "exit now and call finalizers"   -- would be IMHO the least
surprising default
          -- (equivalent to C exit(), and to return from main progrm)
   - "exit now and call finalizers and close the state"
          -- would be the same as current os.exit(code, true)

Phil