lua-users home
lua-l archive

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

2009/11/5 Roberto Ierusalimschy <>:
> Lua does not build an AST; it generates code on the fly. For the syntax
> part, you have to look at lparser.c, function 'primaryexp', case '['.
> But of course you must know what code you want to generate for that
> syntax. Do you plan to make m[i, j] the same as m[i][j]?


I'm planning to translate the code like that:

m[i, j]         => __index(m, i, j)
m[i, j] = v    => __newindex(m, i, j, v)

So all the indexes will be feeded to the __index or __newindex
metamethods in the order. I guess that the variable number of
arguments is not a problem: the metamethods are supposed to check how
many arguments and act accordingly.

The nested indexing method you was thinking about is complicated and
not interesting, I think.

So, for the parser modification I should be able to do it. I'm more
worried about the code generation. May be is not that difficult but I
will need some hints.