lua-users home
lua-l archive

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


>From the Lua 5.1 manual, section 2.5.5: "The length of a table t is
defined to be any integer index n such that t[n] is not nil and t[n+1]
is nil; moreover, if t[1] is nil, n can be zero". For the table {nil,
"x"}, the length operator can return 0 or 2, and it is left
unspecified as to when or why which will be returned. The manual does
not state that tables with identical contents will have the same
length.

On Sun, Sep 20, 2009 at 8:54 PM, Wesley Smith <wesley.hoke@gmail.com> wrote:
> 2 identical tables, 2 different lengths:
>
> res = {nil, "x"}
> res2 = {}
> res2[1] = nil
> res2[2]=  "x"
>
> print(#res, #res2)  ---->>   2, 0
>
> I would expect both to have length 0, but the former has length 2.
> This smells like a bug to me.
>
> wes
>