lua-users home
lua-l archive

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


On Tuesday 23 January 2007 6:57 pm, Jimmie Houchin wrote:
> So I don't understand why I am getting a size of 0 for a table of 10 items?

the '#' operator works only for 'arrays' that is, tables indexed by numbers 
from 1 to n, without holes.

there's not a general 'table size' operator in Lua


> Also I have lots of tables indexed by strings of digits as above.
> But if I try to access them via
>
>  > =items.0007126409
>
> stdin:1: '<eof>' expected near '.0007126409'
>
> doesn't work, but this does.
>
>  > return items['0007126409']
>
> table: 0x8089bf0

from the manual:

"The syntax var.Name is just syntactic sugar for var["Name"]"

note that 'Name' isn't any kind of string; also from the manual:

"Names (also called identifiers) in Lua can be any string of letters, digits, 
and underscores, not beginning with a digit. This coincides with the 
definition of names in most languages."

so, your table's keys are not 'Names', since they begin with a digit

-- 
Javier

Attachment: pgpZSbrKUGOV_.pgp
Description: PGP signature