lua-users home
lua-l archive

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


On Mon, Nov 16, 2015 at 6:28 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
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).

I do not think I understand how that will work. I understand that the transaction thing, when initialized, gets a finalizer, which is a function of some arguments, and those arguments will be finalized. But how do you specify which argument is which?

Cheers,
V.