Functions are only useful if we can call them. To call a function the following syntax is used:
print("Hello, World!")
We're calling the print
function. Using the argument "Hello, World"
. As is obvious, this will print Hello, World
to the output stream. The returned value is accessible, just like any other variable would be.
local added = add(10, 50) -- 60
Variables are also accepted in a function's parameters.
local a = 10
local b = 60
local c = add(a, b)
print(c)
Functions expecting a table or a string can be called with a neat syntactic sugar: parentheses surrounding the call can be omitted.
print"Hello, world!"
for k, v in pairs{"Hello, world!"} do print(k, v) end