aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-04-25 16:36:33 +0800
committerLi Jin <dragon-fly@qq.com>2022-04-25 16:36:33 +0800
commit397bb4820addecbd4b8441614079d2b9b50fd74d (patch)
treeaf180900e3b6ec6d029bc37993450aa369546fbd
parentcfbabdc579795cb34f3b601ce1aee4443951e2ba (diff)
downloadyuescript-397bb4820addecbd4b8441614079d2b9b50fd74d.tar.gz
yuescript-397bb4820addecbd4b8441614079d2b9b50fd74d.tar.bz2
yuescript-397bb4820addecbd4b8441614079d2b9b50fd74d.zip
update doc.
-rwxr-xr-xdoc/docs/doc/README.md121
1 files changed, 80 insertions, 41 deletions
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
360</pre> 360</pre>
361</YueDisplay> 361</YueDisplay>
362 362
363### Appending to Tables 363### Table Appending
364The **[] =** operator is used to append values to tables. 364The **[] =** operator is used to append values to tables.
365 365
366```moonscript 366```moonscript
@@ -374,6 +374,45 @@ tab[] = "Value"
374</pre> 374</pre>
375</YueDisplay> 375</YueDisplay>
376 376
377### Table Spreading
378
379You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals.
380
381```moonscript
382parts =
383 * "shoulders"
384 * "knees"
385lyrics =
386 * "head"
387 * ...parts
388 * "and"
389 * "toes"
390
391copy = {...other}
392
393a = {1, 2, 3, x: 1}
394b = {4, 5, y: 1}
395merge = {...a, ...b}
396```
397<YueDisplay>
398<pre>
399parts =
400 * "shoulders"
401 * "knees"
402lyrics =
403 * "head"
404 * ...parts
405 * "and"
406 * "toes"
407
408copy = {...other}
409
410a = {1, 2, 3, x: 1}
411a = {4, 5, y: 1}
412merge = {...a, ...b}
413</pre>
414</YueDisplay>
415
377### Metatable 416### Metatable
378 417
379The **#** operator can be used as a shortcut for metatable manipulation. 418The **#** operator can be used as a shortcut for metatable manipulation.
@@ -606,45 +645,6 @@ tb =
606</pre> 645</pre>
607</YueDisplay> 646</YueDisplay>
608 647
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
648## Module 648## Module
649 649
650### Import 650### Import
@@ -1979,9 +1979,30 @@ print func_b! -- prints table object
1979 1979
1980This is done to avoid the needless creation of tables for functions that don’t need to return the results of the loop. 1980This is done to avoid the needless creation of tables for functions that don’t need to return the results of the loop.
1981 1981
1982## Repeat Loop
1983
1984The repeat loop comes from Lua:
1985
1986```moonscript
1987i = 10
1988repeat
1989 print i
1990 i -= 1
1991until i == 0
1992```
1993<YueDisplay>
1994<pre>
1995i = 10
1996repeat
1997 print i
1998 i -= 1
1999until i == 0
2000</pre>
2001</YueDisplay>
2002
1982## While Loop 2003## While Loop
1983 2004
1984The while loop also comes in two variations: 2005The while loop also comes in four variations:
1985 2006
1986```moonscript 2007```moonscript
1987i = 10 2008i = 10
@@ -2002,6 +2023,24 @@ while running == true do my_function!
2002</pre> 2023</pre>
2003</YueDisplay> 2024</YueDisplay>
2004 2025
2026```moonscript
2027i = 10
2028until i == 0
2029 print i
2030 i -= 1
2031
2032until running == false do my_function!
2033```
2034<YueDisplay>
2035<pre>
2036i = 10
2037until i == 0
2038 print i
2039 i -= 1
2040until running == false do my_function!
2041</pre>
2042</YueDisplay>
2043
2005Like 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. 2044Like 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.
2006 2045
2007## Continue 2046## Continue