[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Array access indirection
- From: Javier Guerra Giraldez <javier@...>
- Date: Sun, 21 Sep 2008 10:34:31 -0500
On Sunday 21 September 2008, Tim Channon wrote:
> rt={}
>
> rt[var]={[pa1]=va1}
>
> rt[var]={[pa2]=va2} -- does not add pair
one important point is that the curly braces _always_ create a new table.
it's a constructor.
and the assignment _always_ replaces any value at the left. that's why it's
not 'adding a pair' in your example.
the usual idiom for building a table piece by piece has already been posted by
Klaus. I usually do something like this:
local rt={}
function addpair (tk,k,v)
local t = rt[tk]
if t == nil then
t ={}
rt[tk] = t
end
t[k] = v
end
--
Javier
Attachment:
signature.asc
Description: This is a digitally signed message part.