lua-users home
lua-l archive

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

On Fri, Mar 14, 2014 at 9:09 AM, Coroutines <> wrote:
On Fri, Mar 14, 2014 at 6:08 AM, Coroutines <> wrote:
> 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()

hmm, I didn't see that os.exit() had changed so much between 5.1 and
5.2 -- I knew about os.exit(boolean) but I didn't know about the 2nd
parameter to close the state too

I also find it pretty odd that os.exit() doesn't close the state by default. That's just asking for cleanup handlers for objects to not get called, leaving things like temporary files and database connections laying around.

Sent from my Game Boy.