From 397bb4820addecbd4b8441614079d2b9b50fd74d Mon Sep 17 00:00:00 2001 From: Li Jin Date: Mon, 25 Apr 2022 16:36:33 +0800 Subject: update doc. --- doc/docs/doc/README.md | 121 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 80 insertions(+), 41 deletions(-) (limited to 'doc') diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 65266cb..ea320bd 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -360,7 +360,7 @@ tb::func! if tb != nil -### Appending to Tables +### Table Appending The **[] =** operator is used to append values to tables. ```moonscript @@ -374,6 +374,45 @@ tab[] = "Value" +### Table Spreading + +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} +``` + +
+parts =
+	* "shoulders"
+	* "knees"
+lyrics =
+	* "head"
+	* ...parts
+	* "and"
+	* "toes"
+
+copy = {...other}
+
+a = {1, 2, 3, x: 1}
+a = {4, 5, y: 1}
+merge = {...a, ...b}
+
+
+ ### Metatable The **#** operator can be used as a shortcut for metatable manipulation. @@ -606,45 +645,6 @@ tb = -### 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} -``` - -
-parts =
-	* "shoulders"
-	* "knees"
-lyrics =
-	* "head"
-	* ...parts
-	* "and"
-	* "toes"
-
-copy = {...other}
-
-a = {1, 2, 3, x: 1}
-a = {4, 5, y: 1}
-merge = {...a, ...b}
-
-
- ## Module ### Import @@ -1979,9 +1979,30 @@ print func_b! -- prints table object This is done to avoid the needless creation of tables for functions that don’t need to return the results of the loop. +## Repeat Loop + +The repeat loop comes from Lua: + +```moonscript +i = 10 +repeat + print i + i -= 1 +until i == 0 +``` + +
+i = 10
+repeat
+  print i
+  i -= 1
+until i == 0
+
+
+ ## While Loop -The while loop also comes in two variations: +The while loop also comes in four variations: ```moonscript i = 10 @@ -2002,6 +2023,24 @@ while running == true do my_function! +```moonscript +i = 10 +until i == 0 + print i + i -= 1 + +until running == false do my_function! +``` + +
+i = 10
+until i == 0
+  print i
+  i -= 1
+until running == false do my_function!
+
+
+ Like for loops, the while loop can also be used an expression. Additionally, for a function to return the accumulated value of a while loop, the statement must be explicitly returned. ## Continue -- cgit v1.2.3-55-g6feb