lua-users home
lua-l archive

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

On Feb 13, 2009, at 3:44 AM, Roberto Ierusalimschy wrote:

My wish for userdata environments is for them to allow nil as the
environment. That way I could easily tell whether or not I had set a
custom environment on a userdata.

But it would require an extra test for nil before any indexing. Can't
you use a fixed table with (or without) a distinguishing field that
you can inspect when you need to know whether there is a custom

Saving a test when indexing is probably a win over doing the test when writing to see whether we need to generate a table. That's a good point that is a little too easy to forget when writing the code. It's been a while since I wrote any code dealing with this, so I can't recall whether there was some particular reason why sharing an empty table until a write occurred was problematic. The one other benefit I had thought of at the time was that it would save the GC from having to repeatedly trace the link to the shared empty table.