Contiguous integer keys starting from 1 always go in the array part.
Keys that are not positive integers always go in the hash part.
Other than that, it is unspecified, so you cannot predict where t[5]
will be stored according to the spec (and it may or may not move between the two, for example if you create then delete t[4]
.)
LuaJIT 2 is slightly different - it will also store t[0]
in the array part.
If you need it to be predictable (which is probably a design smell), stick to pure-array tables (contiguous integer keys starting from 1 - if you want to leave gap use a value of false
instead of nil
) or pure hash tables (avoid non-negative integer keys.)