lua-users home
lua-l archive

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

On Sat, Feb 14, 2009 at 12:39 PM, Sam Roberts <> wrote:
> On Fri, Feb 13, 2009 at 6:18 AM, Roberto Ierusalimschy
> <> wrote:
> 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 =
>  ...
>  return
> end

It seems vaguely like misuse of tables; nothing's being stored,
nothing's being hashed, a table is being created when all we really
need is the metamethod.  (I realize it's just an example.)  I think
I'd prefer using newproxy.

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

Good question.  I could have sworn there was something on the wiki
mentioning this, but now I can't find it.