lua-users home
lua-l archive

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


> 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