Skip to main content

Things to Note When Learning Lua

  • Array indices start from 1 (unlike C-like languages that start from 0)
  • string.len returns the byte count, not the number of characters
  • All uninitialized variables are nil; assigning nil to a table field deletes it
  • Only nil and false are falsy; every other value is truthy, including 0
  • Strings and numbers are automatically converted in arithmetic and comparisons, e.g. a = '1' + 2
  • Concatenate strings and numbers with .., e.g. a = '1' .. 2
  • Do not compare two floating-point numbers with ==, e.g. avoid if 89.7 == (3 * 29.9) then
  • A floating-point number that can be exactly represented as an integer equals that integer (e.g. 1.0 == 1)