diff options
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -42,6 +42,48 @@ f! | |||
42 | 42 | ||
43 | The original Moonscript language 0.5.0 support can be found in the `0.5.0` branch. Moonscript with new features is in the master branch. Here are the new features introduced in MoonPlus. | 43 | The original Moonscript language 0.5.0 support can be found in the `0.5.0` branch. Moonscript with new features is in the master branch. Here are the new features introduced in MoonPlus. |
44 | 44 | ||
45 | * Add macro functions. | ||
46 | ```Moonscript | ||
47 | -- file 'macro.moon' | ||
48 | export macro block config = (debugging = true)-> | ||
49 | global debugMode = debugging == "true" | ||
50 | "" | ||
51 | |||
52 | export macro block asserts = (cond)-> | ||
53 | debugMode and "assert #{cond}" or "" | ||
54 | |||
55 | export macro expr assert = (cond)-> | ||
56 | debugMode and "assert #{cond}" or "#{cond}" | ||
57 | |||
58 | $config! | ||
59 | |||
60 | -- file 'main.moon' | ||
61 | import 'macro' as {:$config, :$assert, :$asserts} | ||
62 | |||
63 | macro expr and = (...)-> | ||
64 | "#{ table.concat {...}, ' and ' }" | ||
65 | |||
66 | $asserts item ~= nil | ||
67 | $config false | ||
68 | value = $assert item | ||
69 | |||
70 | if $and f1!, f2!, f3! | ||
71 | print "OK" | ||
72 | ``` | ||
73 | Compiles to: | ||
74 | ```Lua | ||
75 | -- file 'macro.moon' | ||
76 | local _module_0 = { } | ||
77 | return _module_0 | ||
78 | |||
79 | -- file 'main.moon' | ||
80 | assert(item ~= nil) | ||
81 | local value = item | ||
82 | if (f1() and f2() and f3()) then | ||
83 | print("OK") | ||
84 | end | ||
85 | ``` | ||
86 | |||
45 | * Move old `export` statement functions to `global` statement to match the `local` statement. | 87 | * Move old `export` statement functions to `global` statement to match the `local` statement. |
46 | 88 | ||
47 | * Change `export` statement behavier to support module management. Moon codes with `export` statement can not explicit return values in root scope. And codes with `export default` can export only one value as the module content. Use cases: | 89 | * Change `export` statement behavier to support module management. Moon codes with `export` statement can not explicit return values in root scope. And codes with `export default` can export only one value as the module content. Use cases: |