Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

Returning a value

Functions don't just take input, they can also return some output to the calling code. This is done through a return value. When a function returns a value, it can be called as part of an expression or as a standalone statement.

If a function is called as a part of an expression, its return value can be assigned to a variable, or used wherever a variable could be used. The following code demonstrates this concept:

-- declare the functionfunction AddTwo(x)  result = x + 2  print (x .. " + 2 = " .. result)  return resultendAddTwo(3) -- calls as statementnine = 7 + AddTwo(5) -- Call as expressionprint ("adding two " .. AddTwo(3)) -- Call as expression

When a function hits a return statement, it returns whatever data follows and ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content