MoonScript, a language that compiles to Lua

Overview of Differences & Highlights

A more detailed overview of the syntax can be found in the documentation.

  • Whitespace sensitive blocks defined by indenting
  • All variable declarations are local by default
  • export keyword to declare global variables, import keyword to make local copies of values from a table
  • Parentheses are optional for function calls, similar to Ruby
  • Fat arrow, =>, can be used to create a function with a self argument
  • @ can be prefixed in front of a name to refer to that name in self
  • ! operator can be used to call a function with no arguments
  • Implicit return on functions based on the type of last statement
  • : is used to separate key and value in table literals instead of =
  • Newlines can be used as table literal entry delimiters in addition to ,
  • \ is used to call a method on an object instead of :
  • +=, -=, /=, *=, %= operators
  • != is an alias for ~=
  • Table comprehensions, with convenient slicing and iterator syntax
  • Lines can be decorated with for loops and if statements at the end of the line
  • If statements can be used as expressions
  • Class system with inheritance based on metatable’s __index property
  • Constructor arguments can begin with @ to cause them to automatically be assigned to the object
  • Magic super function which maps to super class method of same name in a class method
  • with statement lets you access anonymous object with short syntax

Serious programming languages have alternative languages that compile.