lua-users home
lua-l archive

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


> Are the functions `coroutine.close()` and `lua_resetthread()` provided
> only to allow to-be-closed variables to be closed immediately (as
> opposed to when the threads are garbage collected)?

Yes.


> I ask because when looking at the sources, it is not clear to me that
> those functions are called during garbage collection.

They are not.


> Supposed I declared a to-be-closed variable in a coroutine, yielded
> the coroutine, but never intended to resume it. Would the to-be-closed
> variable in the coroutine ever be closed without explicitly calling
> `coroutine.close()`?

No. The manual is explicit about that:

  If a coroutine yields and is never resumed again, some variables
  may never go out of scope, and therefore they will never be closed.
  (These variables are the ones created inside the coroutine and in
  scope at the point where the coroutine yielded.)  Similarly, if a
  coroutine ends with an error, it does not unwind its stack, so it does
  not close any variable.  In both cases, you can either use finalizers
  or call @Lid{coroutine.close} to close the variables.  However, if
  the coroutine was created through @Lid{coroutine.wrap}, then its
  corresponding function will close the coroutine in case of errors.

-- Roberto
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org