[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Reaching a table element - . and  differs?
- From: Enrico Colombini <erix@...>
- Date: Sat, 20 Feb 2010 11:32:14 +0100
No matter if I use return t.id or t.a, the returning value is nil. After
that I used return t[id], and strange, that works perfectly. Can
somebody say me, what is the difference between . and ? Because the
reference manual says:
"The language supports this representation by providing a.name as
syntactic sugar for a["name"]. There are several convenient ways to
create tables in Lua (see §2.5.7)."
t.id is the field indexed by the string "id" of the table t.
t[id] is the field indexed by the *value* contained in the variable
'id', which is what you probably want.