There is a certain function, it returns many values. You can always take, for example, the third value with _,_,A=func() . But the problem is that this function always returns a different number of values. I need to send all values ​​received from function to an array. On a specific example, it was found that in some circumstances the function always returns 7 values. However, in the case of arr=func() there were 57 values ​​in arr. From this I conclude that it is necessary to add each value to an array when the function is first called in a loop. Something like for i,val in func() do arr[#arr+1]=val end , where val is the i-th function return value.

    1 answer 1

    Arrays in lua are implemented as tables.

    You can assign all returned values ​​at once as follows:

     arr = { func() } 

    That is, add curly braces.

    • Please tell me how you can immediately refer to a specific argument? Suppose a function returns several elements, I send them to a table using the above example. arr = {func ()}. Next to access some element I use arr [index]. Is it possible to immediately refer to a specific index? {func ()} [index] does not work. upd: already found the answer. rawget ({func ()}, index) - Gleb