lua-users home
lua-l archive

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


Hi,

Lisa Parratt wrote:
> Surely if table.foreach no longer iterates over *each* element in a 
> table in all instances, it should no longer be called foreach?

As Wim already pointed out this cannot happen with table.foreach().

You are talking about table.foreachi() which is only defined
for compact tables (*).

And since table.foreachi() ultimately uses the same mechanism
as table.getn(), the results for non-compact tables have changed
with 51w6 of course.

Morale of the story: don't use any of these with non-compact tables:

  #t

  ipairs()
  unpack()
  getn()             [Just noticed: why is this still there?]
  table.getn()
  table.foreachi()
  table.insert()
  table.remove()
  table.concat()
  table.sort()

  luaL_getn()
  lua_objsize()

(*) A compact table is defined as a table where the relationship
      t[i] ~= nil or t[i+1] == nil
    holds for all positive integers i.
    More colloquially this is a table that 'has no holes'.

Bye,
     Mike