lua

return statement

Returning a value

Return values can be executed by implementing the return statement within a function. This output can be called as part of an expression or it can be assigned within a variable. 
We cover this concept by declaring a function:

Lua
local function addNumber(num)
    local result = num + 7
    print(result)
    return result
end

As the previous code demonstrates, we have a simple function that returns the value stored inside the result variable which depends on the number you want to add as the function argument.

Calling the function as part of an expression could be like this:

Lua
local expression = 5 + addNumber(10)    -- Call as expression
print("expression = " .. expression)

local value = addNumber(15) -- Returning result inside value variable
print("value = " .. value)

By running this code, you can see:

go/inside/your/project/folder/
$ lua filename.lua
expression = 22
value = 22

Returning multiple values

Lua has a feature that many other programming languages don't have, it's the ability to return multiple values.
These values are represented as a comma separated list:

Lua
local function doubleAndTriple(num)
    local double = num * 2
    local triple = num * 3
    return double, triple
end

Now it's time to call this function with a number and return its double and triple values within two variables:

Lua
local double, triple = doubleAndTriple(10)
print("Double should be " .. double)
print("Triple should be " .. triple)

Your output should look like this:

$ lua filename.lua
Double should be 20
Triple should be 30

Go take a look at this video, it may really help you!

programming language lua return a value return multiple values
Expand your knowledge about this topic