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 #?



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).



[Please log in to post a comment]