lua-users home
lua-l archive

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


[snip]

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.

I think you will find that if you do the following it will give what you want

print(t1[tmp])

This will access the member of the t1 table with the value of tmp, the state t1.tmp is syntactic sugar for t1['tmp'], which is access the member who key is the string "tmp".

Hope this helps.

Andrew.