[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Detecting read or write access in __index metamethod
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 15 Dec 2010 15:27:07 -0200
> The much graver problem than only creating on write access is that you
> want a.b.c.d to nil if not defined. Not some sort of tracking table.
> This cannot work, since there is no way to tell in an __index if this
> is the last element or not and to return some table that helps
> tracking following indexes or if it should return nil already.
Can't you set an __index for nil that returns nil?
I think this has been suggested before, perhaps by me :-)
> debug.setmetatable(nil,{__index=function () return nil end})
> =a.b
nil
> return a.b.c
nil