diff options
author | Li Jin <dragon-fly@qq.com> | 2020-03-05 16:40:20 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-03-05 16:40:20 +0800 |
commit | 9b7ea58d16457e1af0ff90c83db27cbc0b1b4c9b (patch) | |
tree | f8a335f1ba1d4318d49a3e28c7009a0bf46cb957 | |
parent | 890fc913737c62c5d7e51636e0535b7b318a0d89 (diff) | |
download | yuescript-9b7ea58d16457e1af0ff90c83db27cbc0b1b4c9b.tar.gz yuescript-9b7ea58d16457e1af0ff90c83db27cbc0b1b4c9b.tar.bz2 yuescript-9b7ea58d16457e1af0ff90c83db27cbc0b1b4c9b.zip |
update readme.
-rw-r--r-- | README.md | 64 |
1 files changed, 63 insertions, 1 deletions
@@ -42,7 +42,69 @@ 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 | * Multi-line comment. | 45 | * Move old `export` statement functions to `global` statement to match the `local` statement. |
46 | |||
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: | ||
48 | ```Moonscript | ||
49 | -- file 'Config.moon' | ||
50 | export default {flag:1, value:"x"} | ||
51 | |||
52 | -- file 'Utils.moon' | ||
53 | export map = (items, func)-> [func item for item in *items] | ||
54 | export filter = (items, func)-> [item for item in *items when func item] | ||
55 | |||
56 | -- file 'main.moon' | ||
57 | import 'Utils' as {:map, :filter} | ||
58 | ``` | ||
59 | Compiles to: | ||
60 | ```Lua | ||
61 | -- file 'Config.moon' | ||
62 | local _module_0 = nil | ||
63 | _module_0 = { | ||
64 | flag = 1, | ||
65 | value = "x" | ||
66 | } | ||
67 | return _module_0 | ||
68 | |||
69 | -- file 'Utils.moon' | ||
70 | local _module_0 = { } | ||
71 | local map | ||
72 | map = function(items, func) | ||
73 | local _accum_0 = { } | ||
74 | local _len_0 = 1 | ||
75 | for _index_0 = 1, #items do | ||
76 | local item = items[_index_0] | ||
77 | _accum_0[_len_0] = func(item) | ||
78 | _len_0 = _len_0 + 1 | ||
79 | end | ||
80 | return _accum_0 | ||
81 | end | ||
82 | _module_0["map"] = map | ||
83 | local filter | ||
84 | filter = function(items, func) | ||
85 | local _accum_0 = { } | ||
86 | local _len_0 = 1 | ||
87 | for _index_0 = 1, #items do | ||
88 | local item = items[_index_0] | ||
89 | if func(item) then | ||
90 | _accum_0[_len_0] = item | ||
91 | _len_0 = _len_0 + 1 | ||
92 | end | ||
93 | end | ||
94 | return _accum_0 | ||
95 | end | ||
96 | _module_0["filter"] = filter | ||
97 | return _module_0 | ||
98 | |||
99 | -- file 'main.moon' | ||
100 | do | ||
101 | local _obj_0 = require('Utils') | ||
102 | map, filter = _obj_0.map, _obj_0.filter | ||
103 | end | ||
104 | ``` | ||
105 | |||
106 | * Add multi-line comment support. | ||
107 | |||
46 | * Usage for symbol `\` to escape new line. Will compile codes: | 108 | * Usage for symbol `\` to escape new line. Will compile codes: |
47 | ```Moonscript | 109 | ```Moonscript |
48 | str = --[[ | 110 | str = --[[ |