diff options
author | Li Jin <dragon-fly@qq.com> | 2020-01-25 17:48:03 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-01-25 17:48:03 +0800 |
commit | ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8 (patch) | |
tree | 427e365939da39f31dbfa755675fb60bb141583d /README.md | |
parent | 4827d200604a086e2ad94edb4257c3abc7a3c4fc (diff) | |
download | yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.tar.gz yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.tar.bz2 yuescript-ed317e62eb1cf98fde4461fc90c6cb1045ebc7e8.zip |
fix Moonscript issue 375.
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 66 |
1 files changed, 61 insertions, 5 deletions
@@ -1,7 +1,7 @@ | |||
1 | # MoonPlus | 1 | # MoonPlus |
2 | 2 | ||
3 |  | 3 |  |
4 | MoonPlus is a compiler adopting features from Moonscript language 0.5.0 and could be 2~4 times faster than the original Moonscript compiler. | 4 | MoonPlus is a compiler with features from Moonscript language 0.5.0 and could be 2~4 times faster than the original Moonscript compiler. |
5 | 5 | ||
6 | ## Features | 6 | ## Features |
7 | 7 | ||
@@ -10,19 +10,75 @@ MoonPlus is a compiler adopting features from Moonscript language 0.5.0 and coul | |||
10 | * Support full Moonscript language features, generate the same Lua codes with original compiler. | 10 | * Support full Moonscript language features, generate the same Lua codes with original compiler. |
11 | * Reserve line numbers from source Moonscript codes in compiled Lua codes to help with debugging. | 11 | * Reserve line numbers from source Moonscript codes in compiled Lua codes to help with debugging. |
12 | 12 | ||
13 | ## Minor Changes | 13 | ## Changes |
14 | 14 | ||
15 | * Can do slash call with Lua keyword. Generate codes from: | 15 | * Add existential operator support. Generate codes from: |
16 | ```Moonscript | 16 | ```Moonscript |
17 | c.repeat.if\then("xyz")\else res | 17 | func?! |
18 | |||
19 | x = tab?.value | ||
20 | |||
21 | print abc?["hello world"]?.xyz | ||
22 | |||
23 | if print and x? | ||
24 | print x | ||
18 | ``` | 25 | ``` |
19 |   to: | 26 |   to: |
27 | ```Lua | ||
28 | if func ~= nil then | ||
29 | func() | ||
30 | end | ||
31 | local x | ||
32 | if tab ~= nil then | ||
33 | x = tab.value | ||
34 | end | ||
35 | print((function() | ||
36 | if abc ~= nil then | ||
37 | local _obj_0 = abc["hello world"] | ||
38 | if _obj_0 ~= nil then | ||
39 | return _obj_0.xyz | ||
40 | end | ||
41 | return nil | ||
42 | end | ||
43 | return nil | ||
44 | end)()) | ||
45 | if print and (x ~= nil) then | ||
46 | print(x) | ||
47 | end | ||
48 | ``` | ||
49 | |||
50 | * Can do slash call with Lua keywords. Generate codes from: | ||
20 | ```Moonscript | 51 | ```Moonscript |
52 | c.repeat.if\then("xyz")\else res | ||
53 | ``` | ||
54 |   to: | ||
55 | ```Lua | ||
21 | local _call_3 = c["repeat"]["if"] | 56 | local _call_3 = c["repeat"]["if"] |
22 | local _call_4 = _call_3["then"](_call_3, "xyz") | 57 | local _call_4 = _call_3["then"](_call_3, "xyz") |
23 | _call_4["else"](_call_4, res) | 58 | _call_4["else"](_call_4, res) |
24 | ``` | 59 | ``` |
25 | 60 | ||
61 | * Add more usage for `import` keyword. Will compile codes from: | ||
62 | ```Moonscript | ||
63 | import 'module' | ||
64 | import "module.part" | ||
65 | import "d-a-s-h-e-s" | ||
66 | import "player" as Player | ||
67 | import "lpeg" as {:C, :Ct, :Cmt} | ||
68 | ``` | ||
69 |   to: | ||
70 | ```Lua | ||
71 | local module = require('module') | ||
72 | local part = require("module.part") | ||
73 | local d_a_s_h_e_s = require("d-a-s-h-e-s") | ||
74 | local Player = require("player") | ||
75 | local C, Ct, Cmt | ||
76 | do | ||
77 | local _obj_0 = require("lpeg") | ||
78 | C, Ct, Cmt = _obj_0.C, _obj_0.Ct, _obj_0.Cmt | ||
79 | end | ||
80 | ``` | ||
81 | |||
26 | * Add feature of `reusing variable` which helps generate reduced Lua codes. For example, MoonPlus will generate codes from: | 82 | * Add feature of `reusing variable` which helps generate reduced Lua codes. For example, MoonPlus will generate codes from: |
27 | ```Moonscript | 83 | ```Moonscript |
28 | with leaf | 84 | with leaf |
@@ -36,7 +92,7 @@ for x in *something | |||
36 | print x | 92 | print x |
37 | ``` | 93 | ``` |
38 |   to: | 94 |   to: |
39 | ```lua | 95 | ```Lua |
40 | leaf.world(1, 2, 3) | 96 | leaf.world(1, 2, 3) |
41 | do | 97 | do |
42 | local g = leaf.what.is.this | 98 | local g = leaf.what.is.this |