lua-users home
lua-l archive

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


Dmitriy Iassenev wrote:

if we try to assign

  b[nil] = {}

then we get error 'table index is invalid', but if we try

   if b[nil] == nil then
      ...
   end

no error is raised. Is it correct behaviour?

Yes.  The manual says:

An access to an indexed variable t[i] is equivalent to a
call gettable_event(t,i).

and

An assignment to an indexed variable t[i] = val is
equivalent to settable_event(t,i,val).

Both of these functions are

not defined or callable in Lua.  We use [them] here only
for explanatory purposes.

Both gettable_event and settable_event use rawget to check
the current value of the table, and rawget's description
says:

index may be any value

settable_event uses rawset to do the setting, and rawset's
description says:

index [must be] any value different from nil

See also <http://lua-users.org/lists/lua-l/2006-05/msg00378.html>.

--
Aaron