lua-users home
lua-l archive

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


Arseny Vakhrushev wrote:
> Exactly! But it seems you do not have to have a separate 'n'
> field in plain Lua because unpack works well with
> {...}-constructed tables. For some reason, this behavior is
> different in LuaJIT.

The behavior of # is very well defined, please see the Lua manual.

But it doesn't have a unique result for arrays with holes. Any Lua
implementation may return _any_ of the possible results for it
(e.g. this depends on non-integer keys, too). In fact, it might
return a different result every time you call it!

You simply cannot rely on the result of # for arrays with holes.
Period. So better fix your code and stop wondering.

--Mike