|
First off, don’t mix in the “hash part vs array part” stuff. The purely internal use of a C language array to store some of the integer keys is just internal plumbing and not related to logical Lua “arrays” (strictly, sequences). Remember a valid sequence might be stored all in the hash part, all in the array part, or partly in both (and this may change during the life of the table). As I said, there are lots of semantic details to sort out, and table.insert() + table.remove() are part of that. One approach is that for a table of length N, table.insert() at indices from 1 to N+1 increases the length of the array (note it's N+1, so append extends the array), and table.remove() at indices from 1 to N decreases the length of the array. An alternate is that they do nothing to the length at all; they are, after all, named “table.insert()” not “array.insert()”. An explicit length is really taking the “.n” idea and making it first-class, so that functions like table.insert() can be “length aware”, and both the C API and Lua API agree on a standard definitive way to manage array lengths. —Tim |