[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Small question about os.exit and __gc
- From: Coroutines <coroutines@...>
- Date: Fri, 14 Mar 2014 06:08:01 -0700
On Fri, Mar 14, 2014 at 6:06 AM, Coroutines <coroutines@gmail.com> wrote:
> On Fri, Mar 14, 2014 at 4:53 AM, Luiz Henrique de Figueiredo
> <lhf@tecgraf.puc-rio.br> 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()