lua-users home
lua-l archive

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

On Tue, Jun 10, 2014 at 11:03 AM, Thiago L. <> wrote:
> I thought # just used the array size? (you know, with OP_NEWTABLE you have
> hash size and array size... I thought # just returned that array size...)

no, the "array part" is an implementation detail and can be resized at
any time.  #t returns an integer that can be the highest integer key
(if there are no holes), no matter what is on the array and hash
parts, or the currently allocated size of either.

a simple example:

> t = {'a','b','c','d','e','f'}
> =#t
> t[6]=nil      -- very unlikely to cause a resize
> =#t

the fact that it's usually within the array part, is an optimization
that can change without affecting the definition of #t