Re: table.remove not shifting keys when Lua file is in bytecode format

  • From: Mike Pall <mikelj-2105@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 21 May 2021 12:08:07 +0200

table.remove() calculates the length of the table to determine
how much to move.

The length of a table in Lua is ambiguous when nil elements are
present. The result may change, depending on the Lua version, Lua
implementation and even runtime characteristics.

This is all spelled out in the Lua manual (for various versions),
e.g. here: https://www.lua.org/manual/5.4/manual.html#3.4.7

In other words: #({ nil, 1 }) can return either 0 or 2. Avoid nil
in arrays, if you want predictable results.

--Mike

Other related posts: