MoonScript v0.2.0
Exactly 3 months ago I released MoonScript. The CoffeeScript inspired language that compiles to Lua. Since then I've both written a lot of MoonScript and enhanced the MoonScript compiler.
Today I'm proud to release v0.2.0. I've got a handful of new features and bug fixes.
You can find the full release notes on my blog: http://leafo.net/posts/moonscript_v020.html
Thanks for checking it out, follow me on twitter for updates or complaints.
Changes
,is used instead of:for delimiting table slice parts.- Class objects store the metatable of their instances in
__base.__baseis also used in inheritance when chaining metatables.
New Things
The Language
- Added key-value table comprehensions.
- Added a
switchstatement. - The body of a class can contain arbitrary expressions in addition to assigning properties.
selfin this scope refers to the class itself. - Class objects themselves support accessing the properties of the superclass they extend (like instances).
- Class objects store their name as a string in the
__nameproperty. - Enhanced the
superkeyword in instance methods. - Bound methods can be created for an object by using
object\function_nameas a value. Called function stubs. - Added
export *statement to export all assigned names following the statement. - Added
export ^statement to export all assigning names that begin with a capital letter following the statement. exportcan be used before any assignment or class declaration to export just that assignment (or class declaration).- Argument lists can be broken up over several lines with trailing comma.
:hellois short hand forhello: helloinside of table literal.- Added
..=for string concatenation. table.insertno longer used to build accumlated values in comprehensions.
The API
- Added
loadfile,loadstring, anddofilefunctions tomoonscriptmodule to load/run MoonScript code. - Added
to_luafunction tomoonscriptmodule to convert a MoonScript code string to Lua string.
The Tools
- Created prebuilt MoonScript Windows executables.
- Wrote a Textmate/Sublime Text bundle.
- Wrote a SciTE syntax highlighter with scintillua.
- Created a SciTE package for Windows that has everything configured.
- Created an online compiler and snippet site using emscripten.
- Watch mode works on all platforms now. Uses polling if
inotifyis not
available.
Standard Library
I'm now including a small set of useful functions in a single module called moon:
require "moon"Documentation is available here.
Bug Fixes
- Windows line endings don't break the parser.
- Fixed issues when using
...within comprehensions when the compiled code uses an intermediate function in the output. - Names whose first characters happen to be a keyword don't break parser.
- Return statement can have no arguments
- argument names prefixed with
@in function definitions work outside of classes work with default values. - Fixed parse issues with the shorthand values within a
withblock. - Numerous other small fixes. See commit log.
Other Stuff
Since the first release, I've written one other project in MoonScript (other than the compiler). It's a static site generator called sitegen. It's what I now use to generate all of my project pages and this blog.