lua-users home
lua-l archive

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

>Lua already has this information readily available. Why not expose it?

Lua does not have this information readily available. It only has the size of
the hash table, which is unrelated to the number of non-nil entries in it.

>This seems incredibly useful, and would be a boon for
>performance for people that need to know these sorts of things without
>iterating over all table elements all the time (or having to modify
>tables they don't own to cache it).

A simple solution, which has come up in the lengthy discussion about getn in
the past, is to use a separate table to cache this info. You'd use your tables
to index this table and store n in it.