lua-users home
lua-l archive

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


On Sun, Sep 21, 2008 at 8:51 AM, Tim Channon <tc@gpsl.net> wrote:
> Thanks folks including those where I did not reply, all helps.

[...]

> rt={} -- new empty table
>
> rt[var]={[pa1]=va1}  -- hint to Lua is subtable and give a it a pair

That's far from a hint -- it explicitly creates a new table and
assigns it to rt[var].  (You didn't note that creating rt used
different syntax than modifying it, but it did, in just the same way
that creating rt[var] above uses different syntax than modifying it
below.)

> rt[var][pa2]=va2   -- Lua now knows it is a table,
>                 --syntax for adding is different!

Syntax for modifying an existing table is not the same as syntax for
creating a new table, it's true.  They're very different things.  Are
you perhaps used to languages where writing a[b] automatically creates
a table (or other associative container) if 'a' doesn't yet exist?
Those languages have arguably disturbing syntax, by having two
different meanings for a[b].

You can get used to either approach, but Lua's makes more sense to me.

-- James