|
What about:
local t = transaction( function( a, b, c )
if c then c:destroy() end
if b then b:clear() end
if a then a:close() end
end )
local a = t( f() )
local b = t( a:foo() )
local c = t( b:bar() )
-- do something with a, b, c
-- ...
t:commit() -- or t:rollback(), or t:cleanup()
No locals declared before initialization, and you could provide a default rollback function that invokes `__gc` metamethods on all stored values (although I find that rather ugly and unsafe).