lua-users home
lua-l archive

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

Am 13.09.2016 um 10:35 schrieb

   Lua 5.3.3  Copyright (C) 1994-2016, PUC-Rio
   > a={}
   > a[1]=1
   > a[2]=nil
   > a[3]=3
   > a[4]=4
   > print(#a)
should returns value 1 but because a[2] is nil, it should return value 1 according book “Programming in Lua (Third edition)” – there is hole in sequence.

No, this is not a bug.  The length operator #, when used on tables, is only defined for sequences.

Above table is not a sequence.  See for details.

btw, "Programming Lua, Fourth Edition" is out, you might consider an "update"...  Especially since
the new edition contains a nice explanation in chapter 5.3 which the length operator on tables
with nil's is such a nice source of confusion...