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

up.x,up.y=up.y,up.x

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.next, node = new, new
could also not evaluate the node from node.next before node is assigned to new, however, this case is explicitly checked in https://github.com/lua/lua/blob/9db4bfed6bb9d5828c99c0f24749eedf54d70cc2/lparser.c#L1330. 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 https://www.lua.org/manual/5.4/manual.html#3.4 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.

Regards,
Xmilia