lua-users home
lua-l archive

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

Francisco Olarte:

 From what I see:

    stat ::= varlist ‘=’ explist
    varlist ::= var {‘,’ var}
    explist ::= exp {‘,’ exp}

It looks like the "expressions" refer only to the RHS ones. Somewhere
above vars are defined using prefixexp and exp , and a comment stating
that may be clarifying.
I think it may be a lack of detail. The manual, IMO, is trying to say that


works somehow like a=up.y, b=up.x, up.x=a, up.y=b, which may not be
obvious. In fact your example, from what I read, is behaving correctly
with all the exp, and is hitting the var[exp] variant of prefixexp
correctly preevaluating the exp part, but failing on the var part.
So, node = new, new
could also not evaluate the node from before node is assigned to new, however, this case is explicitly checked in Why even do this check in the first place if the prefix-expression parts do not need to be evaluated before the assignments? Further, from I would assume that prefixexp are also expressions.
And if by expressions only the RHS is meant the example:

Thus the code

i = 3
i, a[i] = i+1, 20
sets a[3] to 20, without affecting a[4] because the i in a[i] is evaluated (to 3) before it is assigned 4.

would be wrong, as i could be assinged 4 before a[i] is evaluated.

It would be nice to know how this is meant to work as the my example is a bit contrived, however, this could happen in a more complex __newindex metamethod which for example calls to other hook functions.