lua-users home
lua-l archive

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


On Fri, Feb 13, 2009 at 6:18 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> Well, one thing needs to be clear: any solution not based on garbage
> collection will not be correct in all cases. More specifically, the
> situation where a coroutine yields while using a resource and later
> becomes garbage (and therefore will never "finish" its use) can
> only be detected through garbage collection.

Would it be easier for people to implement finalization if tables
supported the __gc metamethod?

I'm thinking I could do something like:

function f()
  local io
  local _ = setmetatable({}, {
          __gc = function() io:close() end
  })
  io = io.open()
  ...
  return
end

I don't recall ever seeing the reason for Lua not supporting __gc for
tables in the mailing lists, what is it?

Sam