lua-users home
lua-l archive

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


>> The __index metamethod receives the nil key, and can act on it, but
>> the __newindex metamethod doesn't; the error is generated before the
>> metamethod is called. This is an undocumented difference from Lua 4, I
>> believe.

> Lua 4 has no __newindex method.

True enough. But it does have a settable method, and that method is
activated on a nil key. Since Lua 5 returns nil for a[nil] rather than
generating an error message (which is also a change), it would be
consistent for it to call __newindex with a nil key. So in some sense, it
is a change in the philosophy of handling nil keys with metamethods.

Not a criticism! Just an observation... it caught me by surprise, is all.

R.