lua-users home
lua-l archive

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


On Thu May 19, 2022 at 1:57 PM CDT, Sean Conner wrote:
> It was thus said that the Great Mason Bogue once stated:
> > Lua 5.4.3  Copyright (C) 1994-2021 Lua.org, PUC-Rio
> > > t = {1, nil, 3}
> > > #t
> > 3
>
>   That's assuming you define the metatable as:
>
> mt =
> {
>   function(t,k)
>     -- blah blah
>   end,
>
>   nil,
>
>   function(t)
>     -- blah blah
>   end
> }
>
> And yes, under Lua 5.4.3, #mt is indeed 3.

as an aside, I consider this to be somewhat strange behavior.

 > n = {nil,nil,nil}
 > #n
 0
 > n = {nil,nil,1}
 > #n
 3
 > table.insert(n,1)
 > #n
 0
 >

I understand why this happens, but shouldn't #n be 0 in both cases?