lua-users home
lua-l archive

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




On Feb 11, 2018, at 8:01 AM, Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:

On Sun, Feb 11, 2018 at 4:55 PM, albertmcchan wrote:
does comma operator always process from left to right ?

It's easy to check that both vanilla Lua and LuaJIT prepare values from left to right and then assign them from right to left:

local t = setmetatable({}, {__newindex =
   function(t, k, v)
      print(k)
   end
})

local function f(v)
   print(v)
end

t.a, t.b = f("c"), f("d")

Output:
c
d
b
a



Yes it’s easy to see this is current implementation behavior. But Lua does not _specify_ this, so if you rely on it in your code be prepared for your code to break on some Lua implementations.

It’s similar to this code in C:

Int i = 1;
I = i++ + ++I;

—Tim