lua-users home
lua-l archive

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

On Sat, Feb 14, 2009 at 5:34 PM, Sam Roberts <> wrote:
>> It seems vaguely like misuse of tables; nothing's being stored,
> Hm, well, lua uses  tables for pretty much everything ;-)

Heheh, fair enough.  :-)

>> 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.
> True, except newproxy() is undocumented, and described by the authors as a hack.
> As far as I can tell, newproxy() exists as a work-around because
> tables don't have __gc.

I think a lot of these problems could solved or avoided if newproxy
were formally recognized by the authors as a useful feature.  It's
already being used in production code, and nobody gasps or raises an
eyebrow when they see it.  It's found acceptance with the real world
Lua community, and gets put to work in situations not necessarily even
involving __gc.  A lot of very talented people are spending time and
brainpower coming up with things to add to the language in order to --
as far as __gc and finalizers are concerned -- duplicate functionality
that's already present.

I believe there's a lesson to be learned in newproxy's widespread use,
but I'm not sure what it is.  It might be "users like/need this
capability, make newproxy legit".  Or it might be "tables really
should have __gc", which would make newproxy mostly redundant.  Wiser
heads than mine will have to decide.  :-)

Of course, newproxy wouldn't address all the issues raised in this
thread, but (IMveryHO) it would be a start.  I'm partial to the "with"
proposal myself, but in the meantime much of my finalization can be
done with newproxy wrappers like others have already posted.