lua-users home
lua-l archive

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


According to the Lua grammar, it should be written:

a = { b = {}, [b.c] = 22 }   -- note '[' ']'

The problem is the {} do not define a scope, so the interpreter looks in
the global scope for b, and it's not there.

So then try:

a = { b = {}, [a.b.c] = 22 }

The problem here is that the right-hand side is evaluated before
performing the assignment to "a".  So at the point where [a.b.c] is
evaluated "a" doesn't yet exist.

If you do:

b = { c = 1 }
a= { b = {}, [b.c] = 22 }

That works, but I think it's not what you wanted.

To get what you wanted, do what Rici suggested.

Hope that helps.

-Kevin

> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br 
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Marc Nijdam
> Sent: Wednesday, August 18, 2004 3:47 PM
> To: Lua list
> Subject: Nested table syntax
> 
> 
> I'm not finding this in the book or the FAQ, so here goes:
> 
> a = {
>     b = {};
>      b.c = 22;
> };
> 
> will fail with a "expected to close '{' at line 1"  on Lua 5.0
> 
> According to the syntax definition in the reference manual this is 
> supposed to work. Am I missing something?
>