lua-users home
lua-l archive

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

It's been about 10 years since my post "state of the Lua nation on resource cleanup" [1].  The only relevant thing that's happened in this area since then was Lua getting pcall + coroutine love in 5.2.

My position on Lua's need for some type of scope exit hook is only stronger these days.  It's not just about resource cleanup.  For example, there are some very interesting concurrency and cancellation control structures being developed as Python libraries [2] [3] which would be cumbersome and much less effective in a language lacking the equivalent of Python's "with" statement.

To summarize the concurrency control structure, called a "nursery": all spawned tasks within the scope block are owned by that scope's context manager, and the scope will not end until all child tasks are completed.  If a child has an exception, all other child tasks will be cancelled and the error will be propagated.  I'm well versed in trying to use Lua function lambdas for this kind of problem.  The result is not satisfying.