diff options
author | Li Jin <dragon-fly@qq.com> | 2022-04-25 13:19:26 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-04-25 13:19:45 +0800 |
commit | 10afeaf30bfe03774c12908235520eebf0c192ee (patch) | |
tree | ca266b04aaea63ea0710a51708d6ef806008b34e /doc/docs | |
parent | 249e1de1d32dda2b60b9116c5a4e538475de0192 (diff) | |
download | yuescript-10afeaf30bfe03774c12908235520eebf0c192ee.tar.gz yuescript-10afeaf30bfe03774c12908235520eebf0c192ee.tar.bz2 yuescript-10afeaf30bfe03774c12908235520eebf0c192ee.zip |
add spread syntax support for table block. fix a gcc compiler issue. update doc.
Diffstat (limited to 'doc/docs')
-rwxr-xr-x | doc/docs/doc/README.md | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index adff569..65266cb 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
@@ -118,14 +118,14 @@ export yuescript = "ζδΉθζ¬" | |||
118 | 118 | ||
119 |  Use Yuescript module in Lua: | 119 |  Use Yuescript module in Lua: |
120 | 120 | ||
121 | * **Case 1** | 121 | * **Case 1** |
122 | Require "your_yuescript_entry.yue" in Lua. | 122 | Require "your_yuescript_entry.yue" in Lua. |
123 | ```Lua | 123 | ```Lua |
124 | require("yue")("your_yuescript_entry") | 124 | require("yue")("your_yuescript_entry") |
125 | ``` | 125 | ``` |
126 |  And this code still works when you compile "your_yuescript_entry.yue" to "your_yuescript_entry.lua" in the same path. In the rest Yuescript files just use the normal **require** or **import**. The code line numbers in error messages will also be handled correctly. | 126 |  And this code still works when you compile "your_yuescript_entry.yue" to "your_yuescript_entry.lua" in the same path. In the rest Yuescript files just use the normal **require** or **import**. The code line numbers in error messages will also be handled correctly. |
127 | 127 | ||
128 | * **Case 2** | 128 | * **Case 2** |
129 | Require Yuescript module and rewite message by hand. | 129 | Require Yuescript module and rewite message by hand. |
130 | ```lua | 130 | ```lua |
131 | local yue = require("yue") | 131 | local yue = require("yue") |
@@ -136,7 +136,7 @@ end, function(err) | |||
136 | end) | 136 | end) |
137 | ``` | 137 | ``` |
138 | 138 | ||
139 | * **Case 3** | 139 | * **Case 3** |
140 | Use the Yuescript compiler function in Lua. | 140 | Use the Yuescript compiler function in Lua. |
141 | ```lua | 141 | ```lua |
142 | local yue = require("yue") | 142 | local yue = require("yue") |
@@ -174,12 +174,12 @@ Usage: yue [options|files|directories] ... | |||
174 | Execute without options to enter REPL, type symbol '$' | 174 | Execute without options to enter REPL, type symbol '$' |
175 | in a single line to start/stop multi-line mode | 175 | in a single line to start/stop multi-line mode |
176 | ``` | 176 | ``` |
177 |   Use cases: | 177 |   Use cases: |
178 |   Recursively compile every Yuescript file with extension **.yue** under current path: **yue .** | 178 |   Recursively compile every Yuescript file with extension **.yue** under current path: **yue .** |
179 |   Compile and save results to a target path: **yue -t /target/path/ .** | 179 |   Compile and save results to a target path: **yue -t /target/path/ .** |
180 |   Compile and reserve debug info: **yue -l .** | 180 |   Compile and reserve debug info: **yue -l .** |
181 |   Compile and generate minified codes: **yue -m .** | 181 |   Compile and generate minified codes: **yue -m .** |
182 |   Execute raw codes: **yue -e 'print 123'** | 182 |   Execute raw codes: **yue -e 'print 123'** |
183 |   Execute a Yuescript file: **yue -e main.yue** | 183 |   Execute a Yuescript file: **yue -e main.yue** |
184 | 184 | ||
185 | ## Macro | 185 | ## Macro |
@@ -606,6 +606,45 @@ tb = | |||
606 | </pre> | 606 | </pre> |
607 | </YueDisplay> | 607 | </YueDisplay> |
608 | 608 | ||
609 | ### Spread Table | ||
610 | |||
611 | You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals. | ||
612 | |||
613 | ```moonscript | ||
614 | parts = | ||
615 | * "shoulders" | ||
616 | * "knees" | ||
617 | lyrics = | ||
618 | * "head" | ||
619 | * ...parts | ||
620 | * "and" | ||
621 | * "toes" | ||
622 | |||
623 | copy = {...other} | ||
624 | |||
625 | a = {1, 2, 3, x: 1} | ||
626 | b = {4, 5, y: 1} | ||
627 | merge = {...a, ...b} | ||
628 | ``` | ||
629 | <YueDisplay> | ||
630 | <pre> | ||
631 | parts = | ||
632 | * "shoulders" | ||
633 | * "knees" | ||
634 | lyrics = | ||
635 | * "head" | ||
636 | * ...parts | ||
637 | * "and" | ||
638 | * "toes" | ||
639 | |||
640 | copy = {...other} | ||
641 | |||
642 | a = {1, 2, 3, x: 1} | ||
643 | a = {4, 5, y: 1} | ||
644 | merge = {...a, ...b} | ||
645 | </pre> | ||
646 | </YueDisplay> | ||
647 | |||
609 | ## Module | 648 | ## Module |
610 | 649 | ||
611 | ### Import | 650 | ### Import |
@@ -981,6 +1020,17 @@ You can write default values while doing destructuring like: | |||
981 | </pre> | 1020 | </pre> |
982 | </YueDisplay> | 1021 | </YueDisplay> |
983 | 1022 | ||
1023 | You can use `_` as placeholder when doing a list destructuring: | ||
1024 | |||
1025 | ```moonscript | ||
1026 | {_, two, _, four} = items | ||
1027 | ``` | ||
1028 | <YueDisplay> | ||
1029 | <pre> | ||
1030 | {_, two, _, four} = items | ||
1031 | </pre> | ||
1032 | </YueDisplay> | ||
1033 | |||
984 | ### Destructuring In Other Places | 1034 | ### Destructuring In Other Places |
985 | 1035 | ||
986 | Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: | 1036 | Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: |