Lua - Functions

Published 2014/03/05 by Admin in LUA

Create a function without parameters

function myFirstLuaFunction()

print("My first lua function was called")

end

Calling the function

myFirstLuaFunction()

 

Create a function with a return value

function mySecondLuaFunction()

return "string from my second function"

end

Calling the function

a=mySecondLuaFunction()

print(a)

 

Create a function with multiple parameters and multiple return values

function myFirstFunctionWithMultipleReturnValues(a,b,c)

return a,b,c,"My first lua function with multiple return values", 1, true

end

Calling the function

a,b,c,d,e,f = myFirstFunctionWithMultipleReturnValues(1,2 , "three")

print(1,b,c,d,e,f)


The following words are all reserved for internal functions in Lua.

These words cannot be used for variable names, but Lua is case sensitive, so 'and' is reserved and can't be a variable, but 'aND, aNd, AND, anD, AnD, And, ANd' are not reserved and can be used as variables.


my coding

This is a collection of all the coding gems I have found and would like to share with the world!