lua-users home
lua-l archive

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


On Sun, Sep 21, 2008 at 4:51 PM, Tim Channon <tc@gpsl.net> wrote:
>
> require"tprint"
>
> var="fred"
>
> pa1="john"
> va1="sam"
> pa2="ken"
> va2="sal"
>
> rt={} -- new empty table
>
> rt[var]={[pa1]=va1}  -- hint to Lua is subtable and give a it a pair
> rt[var][pa2]=va2   -- Lua now knows it is a table,
>                 --syntax for adding is different!
>
> var="eek"  -- change table
>
> rt[var]={[pa1]=va1}
> rt[var][pa2]=va2
>

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.