lua-users home
lua-l archive

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

On Fri, Mar 14, 2014 at 6:06 AM, Coroutines <> wrote:
> On Fri, Mar 14, 2014 at 4:53 AM, Luiz Henrique de Figueiredo
> <> wrote:
>>> a = {__gc = function() print'exit' end}
>>> setmetatable(a,a)
>>> os.exit()
>>> -> nothing to print.
>>> But if i exit with combination <Ctrl+d>  all Ok.
>> os.exit() terminates the process there and then.
>> <Ctrl+d> terminates the session cleanly, calling lua_close,
>> which then calls the GC methods.
> see I would have expected the opposite... because in C you have exit()
> and at_exit(), I thought lua_close() would be called at_exit() by the
> interpreter.  Doing ctrl + d would be more "instantaneous"?  Kinda
> wish both had called the __gc eitherway ~

er, I mean atexit(), not at_exit().  I wish the standard lua
interpreter (embedding example?) registered a function to lua_close()
the main state with atexit()