lua-users home
lua-l archive

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


On Wed, Aug 18, 2004 at 05:05:19PM -0700, Marc Nijdam wrote:
> a = {
>   b = {};
>   [b.c] = 22
> }
> 
> 
> which give "b not defined globally". Placing 'a' in front of this shows 
> why this is declarative.. a is not defined yet.

Also, the above code means something quite different to what you were trying
to achieve, I think. To understand, try this example:

x = { y = "z" }
a = { [x.y] = 22 }

The effect is the same as:

a = { z = 22 }

or:

a = { ["z"] = 22 }

This is, the expression inside the square brackets is evaluated, and
the resulting value is used as the table key. No change is made to the
'x' table in this instance.

It's perhaps unfortunate that similar syntax is used for an assignment
statement in normal code, and for a key-value pair in a table
constructor. They really are quite distinct things.

> Thanks for the slap, feel much better now :-)

Well, my apologies anyway; it wasn't supposed to be a slap.

-- Jamie Webb