Re: Incorrect behaviour between tables in luajit and lua

  • From: Szabó Antal <szabo.antal.92@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 20 Oct 2014 22:22:27 +0200

2014-10-20 22:17 GMT+02:00 Eduardo Barthel <edub4rt@xxxxxxxxx>:
> While using LuaJIT in my apps I found this bug while declaring a new table
> with "nil" value in the middle, read the following examples, while in Lua
> the output is 3 in LuajIT is 1.

This is not a bug, see: http://www.lua.org/manual/5.1/manual.html#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 a regular array, with non-nil values from 1 to a
given n, its length is exactly that n, the index of its last value. If
the array has "holes" (that is, nil values between other non-nil
values), then #t can be any of the indices that directly precedes a
nil value (that is, it may consider any such nil value as the end of
the array)."

Other related posts: