lua-users home
lua-l archive

Re: Auto-closing with loops

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


On Friday, July 20, 2018 04:55:49 PM pocomane wrote:
> It is not difficult to implement in lua a couple of functions that let
> you to write:
> 
> ```
> local sequence = 'start'
> 
> barrier(function() -- Protect code region
> local a = {}
> 
> setfinalizer(a, function(x) -- Call on scope exit
> assert(a == x)
> sequence = sequence .. '; closing a'
> end)
> 
> sequence = sequence .. '; using a'
> error('an error')
> end)
> 
> assert(sequence == 'start; using a; closing a')
> ```
This thread gives me a great sense of déjà vu.
http://lua-users.org/lists/lua-l/2015-11/msg00164.html
-- 
tom <telliamed@whoopdedo.org>

AltStyle によって変換されたページ (->オリジナル) /