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

Any number of arguments

Unlike other programming languages, in Lua you don't have to provide the same number of arguments as a function's declaration has. For example, adding more arguments than is declared will simply ignore the extra arguments:

-- Declare the function, takes two argumentsfunction AddAndPrint(x, y)  local result = x + y;  print (x .. "+" .. y .. "=" .. result)end-- Call the function a few timesAddAndPrint(2, 3, 7) -- Will print 2+3=5AddAndPrint(4, 5, 8, 9, 10) -- Will print 4+5=9AddAndPrint(6, 7, 11, 12, 14) -- Will print 6+7=13

On the other hand, if you add less arguments than the declaration has, the missing variables will get a value of nil:

-- Declare the function, takes two argumentsfunction PrintValues(x, y) print ("x: ...
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