July 2018
Beginner
202 pages
5h 42m
English
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: ...