From 10afeaf30bfe03774c12908235520eebf0c192ee Mon Sep 17 00:00:00 2001 From: Li Jin <dragon-fly@qq.com> Date: Mon, 25 Apr 2022 13:19:26 +0800 Subject: add spread syntax support for table block. fix a gcc compiler issue. update doc. --- doc/docs/doc/README.md | 68 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 9 deletions(-) (limited to 'doc/docs') 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 = "ζδΉθζ¬"  Use Yuescript module in Lua: -* **Case 1** +* **Case 1** Require "your_yuescript_entry.yue" in Lua. ```Lua require("yue")("your_yuescript_entry") ```  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. -* **Case 2** +* **Case 2** Require Yuescript module and rewite message by hand. ```lua local yue = require("yue") @@ -136,7 +136,7 @@ end, function(err) end) ``` -* **Case 3** +* **Case 3** Use the Yuescript compiler function in Lua. ```lua local yue = require("yue") @@ -174,12 +174,12 @@ Usage: yue [options|files|directories] ... Execute without options to enter REPL, type symbol '$' in a single line to start/stop multi-line mode ``` -  Use cases: -  Recursively compile every Yuescript file with extension **.yue** under current path: **yue .** -  Compile and save results to a target path: **yue -t /target/path/ .** -  Compile and reserve debug info: **yue -l .** -  Compile and generate minified codes: **yue -m .** -  Execute raw codes: **yue -e 'print 123'** +  Use cases: +  Recursively compile every Yuescript file with extension **.yue** under current path: **yue .** +  Compile and save results to a target path: **yue -t /target/path/ .** +  Compile and reserve debug info: **yue -l .** +  Compile and generate minified codes: **yue -m .** +  Execute raw codes: **yue -e 'print 123'**   Execute a Yuescript file: **yue -e main.yue** ## Macro @@ -606,6 +606,45 @@ tb = </pre> </YueDisplay> +### Spread Table + +You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals. + +```moonscript +parts = + * "shoulders" + * "knees" +lyrics = + * "head" + * ...parts + * "and" + * "toes" + +copy = {...other} + +a = {1, 2, 3, x: 1} +b = {4, 5, y: 1} +merge = {...a, ...b} +``` +<YueDisplay> +<pre> +parts = + * "shoulders" + * "knees" +lyrics = + * "head" + * ...parts + * "and" + * "toes" + +copy = {...other} + +a = {1, 2, 3, x: 1} +a = {4, 5, y: 1} +merge = {...a, ...b} +</pre> +</YueDisplay> + ## Module ### Import @@ -981,6 +1020,17 @@ You can write default values while doing destructuring like: </pre> </YueDisplay> +You can use `_` as placeholder when doing a list destructuring: + +```moonscript +{_, two, _, four} = items +``` +<YueDisplay> +<pre> +{_, two, _, four} = items +</pre> +</YueDisplay> + ### Destructuring In Other Places Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: -- cgit v1.2.3-55-g6feb