lua-users home
lua-l archive

Re: Array access indirection

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


Mark Meijer wrote:
> 2008年9月21日 Javier Guerra Giraldez <javier@guerrag.com>:
> AFAIK, any keys present in a table constructor have to be immediate
> values. At any other place, you can use any expression you like to
> access tables (aside from some exceptions, such as nil, or keywords or
> symbols as names when using the dot notation).
> 
> And of course, any table can be a key (or a value, for that matter) in
> any other table (but again, in table constructors, any keys have to be
> immediate values, e.g. another table constructor).
> 
> Hope this covers it.
It might do.
I've put something simple together which might give a clue on what I mean.
require"tprint"
var="fred"
pa1="john"
va1="sam"
pa2="ken"
va2="sal"
rt={}
rt[var]={[pa1]=va1}
rt[var]={[pa2]=va2} -- does not add pair
tprint(rt)

AltStyle によって変換されたページ (->オリジナル) /