Defining and Calling Functions

Functions in Lua are first-class values, meaning they can be stored in variables, passed to other functions, and returned as results.

Defining a Function:

function greet()
  print("Hello from Lua!")
end

Calling a Function:

greet() -- Output: Hello from Lua!

Storing in Variables:

sayHello = function()
  print("Hi!")
end

sayHello()

This shows how flexible functions are in Lua.

← PrevNext →