lua-users home
lua-l archive

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


On 10/4/06, Glenn Maynard <glenn@zewt.org> wrote:
Rather,

  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

Note that an array can have holes; they're even mentioned further down
in 2.5.5.

> And you want to make sure the table meets those conditions (why? :-),
> then doing pairs() and checking each key is >=1 and <= #t, and that you
> see exactly #t of them, should work. I don't think that pairs() will
> return a key if the value is nil.

... and integral.

(I also have some difficulty thinking of a real use for wanting to know
this; if someone gives an example, it may be easier to know exactly what's
wanted.)

I am writing a bridge between Lua and JavaScript. If it is known that
a table is actually an array, one can then create a JS array rather
than a generic JS Object.
The 'pairs' mechanism is easy enoug to use in Lua code. I'm just
wondering if there's a good way of doing the same from C.

Thanks,
Ashutosh