[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Newbie questions regarding luasocket, tables
- From: Tomas Guisasola Gorham <tomas@...>
- Date: Tue, 8 May 2007 16:14:08 -0300 (BRT)
> > In this case, I think the argument for having #t return the real table
> > size isn't that it adds a feature, but that it removes an annoying
> > special case, leading to a more regular and predictable language.
>
> I don't think so. For instance, many programs use tables with both
> "keys" and "indices", such as this:
>
> polyline = { color = "red", thickness = 4;
> {0, 0}, {3.5, 4.3}, ...
> }
Many times I use the array-part to indicate some of the fields
or to determine the order of them:
data = { "name", "id", "tel",
name = "Tomás",
id = 12,
tel = "12345678",
type = "programmer",
}
In this case, it is useful to traverse the array-part (to get
the order or the valid fields) and index the record-part to get the
real values:
for _, key in ipairs(data) do
print(key, data[key])
end
> When they iteract over the indices, they want the size of the array part,
> not of the entire table.
Sure! I cannot remember when I had to count all of the entries
in a table, as someone already pointed out.
Tomás
- References:
- Newbie questions regarding luasocket, tables, mpb
- Re: Newbie questions regarding luasocket, tables, Shmuel Zeigerman
- Re: Newbie questions regarding luasocket, tables, Luiz Henrique de Figueiredo
- Re: Newbie questions regarding luasocket, tables, Sam Roberts
- Re: Newbie questions regarding luasocket, tables, Roberto Ierusalimschy
- Re: Newbie questions regarding luasocket, tables, Sam Roberts
- Re: Newbie questions regarding luasocket, tables, Roberto Ierusalimschy