lua-users home
lua-l archive

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


This flexible syntax support is one of the reasons I just can't get enough Lua, thanks to the writers of the language :D

I once tried to make a C++ like syntax for declaring classes: https://github.com/abhijitnandy2011/DSLsBasedOnLua/blob/master/cpp/cpp.lua#L186

Got stuck at trying to realize a syntax like:
int m
It had to be:
int 'm'

Cheers!
Abhijit

On Tue, Jul 30, 2019 at 6:21 AM Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
>    ( a * b ).c()[ d ].e:f()
>
>  Other than being a function (method?) call to f, what is the meaning
> of the parse of it, step by step, from left to right?

Here is the output of luac -l -p on that code (Lua 5.1, whose opcodes
has easier to read):

1 [1] GETGLOBAL 0 -1 ; a
2 [1] GETGLOBAL 1 -2 ; b
3 [1] MUL       0 0 1
4 [1] GETTABLE 0 0 -3 ; "c"
5 [1] CALL     0 1 2
6 [1] GETGLOBAL 1 -4 ; d
7 [1] GETTABLE 0 0 1
8 [1] GETTABLE 0 0 -5 ; "e"
9 [1] SELF     0 0 -6 ; "f"
10 [1] CALL     0 2 1