Re: hello and unpack() issue.

  • From: Javier Guerra Giraldez <javier@xxxxxxxxxxx>
  • To: LuaJIT <luajit@xxxxxxxxxxxxx>
  • Date: Fri, 10 Sep 2021 09:23:00 -0500

On Fri, 10 Sept 2021 at 09:01, Matt Gerassimoff <mgeras@xxxxxxxxx> wrote:


`print(unpack({1,nil,2,nil,3,n=5}))`
I get:
`1`
from my version.  When I do the same thing in lua 5.1 I get:
`1 nil 2 nil 3'
I've also tried lua 5.2 and beyond which returns the same results as 5.1.

I've tested this on x64 and arm64 architectures. I don't believe that would 
be expected behaviour.  If there is somewhere to submit bug reports, I'll 
gladly do that.

unpack is defined in terms of the `#` operator

from the 5.1 docs:  "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)."

so, yes, it is expected behaviour.

-- 
Javier

Other related posts: