Basically Lua is really dumb, so rather than make # mean "size" like any normal human being capable of any modicum of rational thought would expect, it only deals with integer indices starting from 1.
function dictionaryCount(d)
count = 0
for key, value in pairs(d) do
count = count + 1
end
return count
end
That should do what you want.
However, bare in mind that while the execution of # is basically free, and doesn't change no matter how large the table, the execution of dictionaryCount scales linearly with how many things are in the table.
If you're familiar with big-O notation, dictionaryCount(d) is O(n)
1 comment
Oooooh. Thank you for useful information!