lua-users home
lua-l archive

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


On Feb 11, 2018, at 11: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


nice trivia, that means 

a, b, c, a = 3 same as a=nil; c=nil, b=nil; a=3

= a
3