lua-users home
lua-l archive

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

Attila wrote:
No matter if I use return 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 as syntactic sugar for a["name"]. There are several convenient ways to create tables in Lua (see §2.5.7)." 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.