Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>t = {[1]=1, [2]=2, [4]=4} -- has a length of 4 </code></pre> <p>Well there's your problem right there; that does not have a length of 4. You might <em>think</em> it does, and <code>#t</code> might return 4. But as far as the Lua API is concerned, the length of this table is <em>undefined</em>.</p> <p><a href="http://www.lua.org/manual/5.1/manual.html#2.5.5" rel="nofollow">Lua 5.1 states</a>:</p> <blockquote> <p>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<a href="http://www.lua.org/manual/5.1/manual.html#2.5.5" rel="nofollow">1</a> 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).</p> </blockquote> <p><a href="http://www.lua.org/manual/5.2/manual.html#3.4.6" rel="nofollow">Lua 5.2 is rather more explicit</a>:</p> <blockquote> <p>the length of a table t is only defined if the table is a sequence, that is, the set of its positive numeric keys is equal to {1..n} for some integer n. In that case, n is its length. Note that a table like</p> </blockquote> <pre><code> {10, 20, nil, 40} </code></pre> <blockquote> <p>is not a sequence, because it has the key 4 but does not have the key 3. (So, there is no n such that the set {1..n} is equal to the set of positive numeric keys of that table.) Note, however, that non-numeric keys do not interfere with whether a table is a sequence. </p> </blockquote> <p>But in both cases, the length is <em>undefined</em>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload