Expressions and Statements

  • Expressions are numeric, relational or string
  • Each has a set of operators that are used in their creation

Arithmetic expressions operators

addition (+) subtraction (-) multiplication (*) division (/) Exponentiation (^) Modulo (%) Unary negation (-variable)

Relational operators

Less than (<) Greater than (>) Less than or equal (<=) Greater than or equal (>=) Equal (==) Not Equal (~=)

Logical Operators

and or not

Precedence Rules

  • Arithmetic, relational, and logical operators
    • follow the standard precedence rules

Assignment

  • The equals sign is assignment
    • Assigns a value to a memory location

variableName = value

  • left-hand side is a reference to a memory location
  • right-hand side evaluates to the value (can be a function reference)

String Concatenation

a = "This is a " .. "string concatenation"

Length of String and Table with integer indices

  • The length operator is the hash (#)

-- string concatenation and length a = "this is a string " .. "concatenation" print(a) b = #a print("The string length is " .. b) -- length of a table with integer indices b = {"Earth", "Mars", "Saturn", "Jupiter"} print (#b)