Lua Cheat Sheet
Comments
Variables
local myVariable = 5
myVariable = 10
myVariable = "Hi!"
MY_VARIABLE = 2.15
Data Types
nil
"I'm a string!"
'I\'m also a string!'
"Hello" .. " " .. "World!"
15
0.56
8.3e10
8.3e+10
8.3e-10
true
false
function YellMessage( message )
local loudMessage
= string.
upper( message )
.. "!"
print( loudMessage )
end
local function AddNumbers( a, b )
return a
+ b
end
local SubtractNumbers
= function( a, b )
return a
- b
end
local function SquareAndCube( a )
return a
^2, a
^3
end
local myTable
= {}
myTable
= {
100,
5,
200,
}
myTable
= {
["My Key"] = "My Value!",
[2] = true,
[false] = function()
print(
"Howdy!" )
end,
[function()
print(
"Hello!" )
end] = true
}
myTable
[ "My Key" ] = "A new value"