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

  • From: Mike Pall <mikelj-2105@xxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 24 May 2021 14:07:25 +0200

Demi Marie Obenour wrote:

On 5/21/21 6:08 AM, Mike Pall wrote:
The length of a table in Lua is ambiguous when nil elements are
present.

Would it be possible to issue a warning when this happens?  Presumably
this would impose significant overhead, so it would need to be
off-by-default, which is fine.  Or would this require significant
changes to the VM?

That would need an expensive traversal of the whole table on every
length operation. And some tricky logic to deal with the split
array/hash part and implicit 'nil' semantics. Such a check could
be added to lj_tab_len() and lj_tab_len_hint().

But I have no plans to do so.

--Mike

Other related posts: