lua-users home
lua-l archive

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


On Wed, Jan 21, 2009 at 4:20 AM, Asko Kauppi wrote:
> Using traditional GC mechanism for these scopes is deterministic, since the
> whole Lua state is cleared at return/error. However, I could survey this a
> little further and maybe add some ease of use way to add "finalizers" to the
> lanes.

In that case, either the caller or callee could have that
responsibility.  For example, the callee could probably do

  local function on_exit(f)
    local o = newproxy(true)
    getmetatable(o).__gc = f
    _G[{}] = o
  end

  on_exit(function() print 'deleting file..' end)

Similarly, in the more general case, one "could" call collectgarbage()
after every pcall to deterministically cleanup most objects, though
relying on this could be more error prone compared to an explicit
mechanism that disposes all objects out of scope, regardless if they
are finalizable.