lua-users home
lua-l archive

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


The behaviour of the "n" field (more specifically, the luaL_[gs]etn
functions) has changed in Lua 5.1(work).  I'm wondering what the
rationale was for this change.

Here is a comparison of the new and old behaviours:

Old luaL_setn(t, n):
  if t.n is a number >= 0, set t.n = n
  else set sizes[t] = n

New luaL_setn(t, n):
  set sizes[t] = n

Old luaL_getn(t, n):
  if t.n is a number >=0, return n
  else if sizes[t] is a number >=0, return sizes[t]
  else count the elements.

New luaL_getn(t, n):
  if sizes[t] is a number >=0, return sizes[t]
  else if t.n is a number >=0, return n
  else count the elements.


Unfortunately, this change means that if you use the "n" field, its
value will not be updated when using the table.insert and table.remove
methods.  This broke some of my scripts, as it was depending on the old
behaviour in which "n" was updated by the table library functions.

Thanks,
Jasmin