[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: question about table elements
- From: jdarling@...
- Date: Thu, 10 Aug 2006 08:09:16 -0700
Below are two solutions to your question, the code that you posted asks
for t2['tmp'] when you want t2[tmp]:
t1 = {
["a"] = 1,
["b"] = 2,
["c"] = 3,
}
t2 = {
["x"] = "a",
}
tmp = t2.x
print(tmp) --> a
print(t1[tmp]) --> a
print(t1[t2.x]) --> a
- Jeremy
"Help I suffer from the oxymoron Corporate Security."
> -------- Original Message --------
> Subject: question about table elements
> From: Ryan Cresawn <cresawn@chass.utoronto.ca>
> Date: Thu, August 10, 2006 9:48 am
> To: Lua list <lua@bazar2.conectiva.com.br>
>
> Lua list,
>
> I'm having a difficult time accessing table elements and I would
> appreciate some help. The code below is test code but it behaves the
> same way that my larger program does.
>
> -- begin example --
>
> t1 = {
> ["a"] = 1,
> ["b"] = 2,
> ["c"] = 3,
> }
>
> t2 = {
> ["x"] = "a",
> }
>
> tmp = t2.x
> print(tmp) --> a
> print(t1.tmp) --> nil
>
> -- end example --
>
> How could I achieve the goal of using the value stored in 't2.x' to
> access 't1.a'? I suspect I'm overlooking something simple and would
> appreciate any advice you may offer.
>
> Ryan