WoW:API getn: Difference between revisions
Jump to navigation
Jump to search
no edit summary
m (Added # operator) |
No edit summary |
||
| Line 21: | Line 21: | ||
> print( #{1,2,3} ) | > print( #{1,2,3} ) | ||
3 | 3 | ||
It seems things are not quite that simple. | |||
See here for details: [http://lua-users.org/wiki/LuaTableSize Lua Table Size Discussion] | |||
Table.getn works as you'd expect if your keys are numeric (i.e. indices). | |||
if your table has keys of other type, table.getn might give you back 0 regardless of how many key-value pairs you've stored in the table. | |||
Quoting from the linked page: | |||
''If the table has an n field with a numeric value, this value is the size of the table. Otherwise, the size is the largest numerical index with a non-nil value in the table.'' | |||
== See Also == | == See Also == | ||