Log In  

test = {}
add(test, {})
print(#test) -- 1
print(count(test)) -- 1
test[1] = nil
print(count(test)) -- 0
print(#test) -- 1

are you maintaining some other method of counting the objects in tables other than counting until you hit nil (I am guessing the answer is yes)? If so, is it faster to use COUNT than #?

P#11703 2015-07-19 19:09 ( Edited 2015-07-22 18:59)

there are some other strange behaviors that I am noticing (I am happy to hear that I am doing something wrong here)

test = {}
add(test, 1)
add(test, 2)
n = test[1]
del(test, n)
print(test[1]) -- returns false

my expectation is that when you delete an element from a numerical array it would be the equivalent of lua's table.remove, i.e. reindex the following elements. (I am also happy to reimplement table.remove, but it seems like a standard use case to me).

P#11766 2015-07-22 14:59 ( Edited 2015-07-22 18:59)

[Please log in to post a comment]