lua-users home
lua-l archive

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


On Friday 11 June 2004 17:47, Dan East wrote:
> 2) In C it possible to determine the number of elements in a table without
> iterating it.

Nope. Lua itself doesn't know. It's possible (but not a good idea) to dig 
around in the internal structures to get the physical table size, which gives 
an upper bound, but that's about it.

The only other possibility is to always set values in the table using a 
function which can record the size (you can't just use __newindex because 
that won't pick up entries being removed). You could make it appear 
transparent using a proxy table (search the list), but that has its own 
issues.

-- Jamie Webb