lua-users home
lua-l archive

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

> To-be-closed variables are a new feature and a safety- and data
> integrity-related one so, IMO, users should be given extremely clear
> information on what are the guarantees of the new mechanisms, otherwise
> they could get a false sense of security and put nasty bugs in their
> program.

Another trap you can fall into is to put a local ... <close> variable
inside a coroutine. There are a number of problems with that:

- you have to explicitly call coroutine.close(thread) to do the
variable cleanup if the coroutine is suspended (has yielded).
- coroutine.close does not work on threads that are not suspended or
dead,  i.e. threads that are waiting for coroutine.resume to return.
- if you call os.exit(<code>, true) from a coroutine no __close
metamethods will be called in any thread, not even the main one.

The behavior of os.exit is in my opinion a bit inconsistent, it
unwinds the stack and closes to-be-closed variables in the main
thread, but only if you call it from that main thread, and it does not
do anything to other coroutines.