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:

local function addNumber(num)
    local result = num + 7
    return result

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:

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:

$ 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:

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

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

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