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
exportkeyword to declare global variables,importkeyword 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 inself!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
__indexproperty- Constructor arguments can begin with
@to cause them to automatically be assigned to the object- Magic
superfunction which maps to super class method of same name in a class methodwithstatement lets you access anonymous object with short syntax
via moonscript.org
Serious programming languages have alternative languages that compile.