Is it possible to create a list of variables from an array on lua?

R, G, B = getColors() 
 function getColors() return {255, 128, 0} end 
  • R, G, B = getColors()[1], getColors()[2], getColors()[3] So it works, but I hope for something shorter - Mr. Black

2 answers 2

Use the table.unpack function:

 R, G, B = table.unpack(getColors()) 

    Understood. It was just necessary to return the variables not by an array, but separated by a comma.

     R, G, B = getColors() 
     function getColors() return 255, 128, 0 end