View Single Post
05-07-12, 07:50 PM   #4
d87
A Chromatic Dragonspawn
 
d87's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 163
http://www.lua.org/source/5.2/ltable.c.html#luaH_getn

{x,y,z} seems to be an "array" notation, which makes sense to have (for example to store function arguments with holes in a table).
When you construct table that way, sizearray variable is filled without checking about holes. Later, when you request table length, it just checks if last element according to sizearray is nil, and if it is, tries to find boundary(non-nil value followed by nil value) manually.
Like in t2 example, it might not be the the boundary you want, so you better strip nils yourself in this case.

Code:
local t3 = {nil, nil, 4, 7, nil, 4}
t3[5]= 2   -- #t3 = 6
t3[7]= 2   -- #t3 = 0
Also, if you try to expand your array, sizearray is recalculated to first boundary it founds.

Edit: i'm late

Last edited by d87 : 05-07-12 at 08:07 PM.
  Reply With Quote