1-- Standard function declaration
2function hello(name)
3 print("Hello, " .. name)
4end
5
6-- Local function declaration
7local function secret_formula(x, y)
8 return x * y + 42
9end
10
11-- Function assigned to a variable
12myfunc = function(a, b)
13 return a - b
14end
15
16-- Method-like function
17local MyTable = {}
18function MyTable:greet()
19 print("Greetings!")
20end
21
22-- Nested function
23function outer()
24 local function inner()
25 print("I am inside")
26 end
27 inner()
28end
29
30hello("User")
31secret_formula(1, 2)
32myfunc(10, 5)
33MyTable:greet()
34outer()