Weirdness: (a[b])()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Weirdness: (a[b])()

Eduardo Ochs-2
Hi list,

Why does Lua interpret something like

              (action["*"])()
          as  action["*"]()()
  and not as  action["*"]()   ?

I have checked it with "luac -l" (both in lua4.0 and in lua3.2), and
the first two expressions are compiled to:

     GETGLOBAL       0       ; action
     GETDOTTED       1       ; *
     CALL            0 1
     CALL            0 0

while the third one becomes:

     GETGLOBAL       0       ; action
     GETDOTTED       1       ; *
     CALL            0 1

This sounds a bit counterintuitive to me, and I haven't been able to
find the explanation in the manual. Also, fifteen minutes of careless
single-stepping through luaY_parser told me nothing...

  Cheers,
    Eduardo Ochs
    http://angg.twu.net/
    http://www.mat.puc-rio.br/~edrx/
    [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Weirdness: (a[b])()

Luiz Henrique de Figueiredo
>Why does Lua interpret something like
>
>              (action["*"])()
>          as  action["*"]()()
>  and not as  action["*"]()   ?

Statements in Lua cannot begin in parentheses.
The line (action["*"])() is not valid Lua code.

Perhaps you had something before it, such as
	a=b
	(action["*"])()
This is read as
	a=b (action["*"])()
which gives the two CALLs.
--lhf