Defining a function

A function declaration starts with the function keyword. After the function keyword, you provide the function name. The name of the function follows the same naming rules as the name of a variable.  

After the name of your function, you have to provide a list of parameters. Parameters are variable names enclosed in parentheses (). The list of parameters may be empty if a function needs no parameters, in which case only opening and closing parentheses are given—().

Once you have declared the list of parameters, you may write the body of the function. The function body is a chunk of code, so like other chunks you need to close the body with the end keyword. The following code demonstrates a simple function:

function PrintSomething()
text1 = "hello"
text2 = "world"
print (text1 .. ", " .. text2)
end

This function definition can be broken down into the following parts:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.198.94