lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

Why is the default pos for tinsert() 'getn(t)+1' and not just 'getn
(t)'?

This produces the suprising (to me) results:

t = {}
tinsert( t, "A" )
tinsert( t, "B" )
tinsert( t, "C" )
-- t[0] = nil <== index 0 is accessable, but tinsert() ignores it?
-- t[1] = A
-- t[2] = B
-- t[3] = C

I know there is a restriction when it come to string index (i.e. they 
start at 1) but there is no such restriction on tables, so why does 
tinsert not start at index 0?

I've searched the list for information about this but came up empty; 
sorry if it's been asked and answered already.

David