lua-users home
lua-l archive

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


Hello guys,

I've got a question on the Lua table structure:

In case of numerical table indices I can use the length operator # to get the number of fields. With one restriction: indices must be incremental without any gaps because the definition is:
"... any integer index n such that t[n] is not nil and t[n+1] is nil ..."

For tables with string indices there is simply no length operator :-(

So far, the only way to get a reliable information about the length of a table is to iterate it by using for i,v in pairs (tbl) and count the field by myself.

For me this is very dissatisfying. :-(

Is there any way to find a length operator for tables independent of the type of its keys?

Cheers,
Eva