lua-users home
lua-l archive

Re: Array access indirection

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


> Just a suggestion, but in addition it would probably suit you more to do:
>
> rt={} -- new empty table
>
> rt[var]={}
> rt[var][pa1]=va1
> rt[var][pa2]=va2
>
> var="eek" -- change table
>
> rt[var]={}
> rt[var][pa1]=va1
> rt[var][pa2]=va2
>
> etc. since you will probably be doing it in a loop anyway, I imagine.
>
> Matthew.
>
my personal preference for nested table style is:
rt = {}
local t = {}
t[pa1] = va1
t[pa2] = va2
rt[var] = t
var="eek"
local t = {}
t[pa1] = va1
t[pa2] = va2
rt[var] = t
if it's in a loop (i.e. the above is unrolled) because it's cleaner in
my view (less "dereferences") and saves table accesses
or even better
rt = {
 [var] = {
 [pa1] = va1,
 [pa2] = va2,
 },
...
}

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