[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Weird __newindex behaviour
- From: Duncan Cross <duncan.cross@...>
- Date: Tue, 22 Sep 2015 16:49:12 +0100
On Tue, Sep 22, 2015 at 4:41 PM, Scott Morgan <blumf@blueyonder.co.uk> wrote:
> Seeing the following behaviour on various version of Lua:
(...)
> It's weird because, surely, if this is a bug, it has already been seen.
> It's such a common pattern. I must be doing something wrong here?
The __newindex metamethod is only triggered when the given index does
not already exist in the table. I believe the generally recommended
solution for catching every assignment is to use a proxy table, i.e.
keep the actual table empty and set up the __index and __newindex
metamethods to redirect accesses to another, hidden table.
-Duncan