[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Reaching a table element - . and [] differs?
- From: Attila <ejjeliorjarat@...>
- Date: Sat, 20 Feb 2010 11:20:35 +0100
Hello!
I am working on a little project, where the C code passes to Lua some
parameters, then I build the basic architecture from it. The type of the
passed value is lightuserdata as I see, and when I used
print(tostring(id)) it wrote: userdata: <address>. I use this as a table
field to store the built table. It works well, but I experience some
strange thing. When I want to select a table, I use this:
function get(id) -- id is that lightuserdata that C core passes
for a in pairs(t) do -- I store my tables in t
if a == id then -- Checked, they are the same
return t.id
end
end
end
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)."
Thanks: Attila