aboutsummaryrefslogtreecommitdiff
path: root/doc/docs
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-04-25 13:19:26 +0800
committerLi Jin <dragon-fly@qq.com>2022-04-25 13:19:45 +0800
commit10afeaf30bfe03774c12908235520eebf0c192ee (patch)
treeca266b04aaea63ea0710a51708d6ef806008b34e /doc/docs
parent249e1de1d32dda2b60b9116c5a4e538475de0192 (diff)
downloadyuescript-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-xdoc/docs/doc/README.md68
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&emsp;Use Yuescript module in Lua: 119&emsp;Use Yuescript module in Lua:
120 120
121* **Case 1** 121* **Case 1**
122Require "your_yuescript_entry.yue" in Lua. 122Require "your_yuescript_entry.yue" in Lua.
123```Lua 123```Lua
124require("yue")("your_yuescript_entry") 124require("yue")("your_yuescript_entry")
125``` 125```
126&emsp;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&emsp;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**
129Require Yuescript module and rewite message by hand. 129Require Yuescript module and rewite message by hand.
130```lua 130```lua
131local yue = require("yue") 131local yue = require("yue")
@@ -136,7 +136,7 @@ end, function(err)
136end) 136end)
137``` 137```
138 138
139* **Case 3** 139* **Case 3**
140Use the Yuescript compiler function in Lua. 140Use the Yuescript compiler function in Lua.
141```lua 141```lua
142local yue = require("yue") 142local 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&emsp;&emsp;Use cases: 177&emsp;&emsp;Use cases:
178&emsp;&emsp;Recursively compile every Yuescript file with extension **.yue** under current path: **yue .** 178&emsp;&emsp;Recursively compile every Yuescript file with extension **.yue** under current path: **yue .**
179&emsp;&emsp;Compile and save results to a target path: **yue -t /target/path/ .** 179&emsp;&emsp;Compile and save results to a target path: **yue -t /target/path/ .**
180&emsp;&emsp;Compile and reserve debug info: **yue -l .** 180&emsp;&emsp;Compile and reserve debug info: **yue -l .**
181&emsp;&emsp;Compile and generate minified codes: **yue -m .** 181&emsp;&emsp;Compile and generate minified codes: **yue -m .**
182&emsp;&emsp;Execute raw codes: **yue -e 'print 123'** 182&emsp;&emsp;Execute raw codes: **yue -e 'print 123'**
183&emsp;&emsp;Execute a Yuescript file: **yue -e main.yue** 183&emsp;&emsp;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
611You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals.
612
613```moonscript
614parts =
615 * "shoulders"
616 * "knees"
617lyrics =
618 * "head"
619 * ...parts
620 * "and"
621 * "toes"
622
623copy = {...other}
624
625a = {1, 2, 3, x: 1}
626b = {4, 5, y: 1}
627merge = {...a, ...b}
628```
629<YueDisplay>
630<pre>
631parts =
632 * "shoulders"
633 * "knees"
634lyrics =
635 * "head"
636 * ...parts
637 * "and"
638 * "toes"
639
640copy = {...other}
641
642a = {1, 2, 3, x: 1}
643a = {4, 5, y: 1}
644merge = {...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
1023You 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
986Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: 1036Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: