diff options
Diffstat (limited to '')
| -rwxr-xr-x | doc/docs/doc/README.md | 121 |
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 |
| 364 | The **[] =** operator is used to append values to tables. | 364 | The **[] =** 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 | |||
| 379 | You can concatenate array tables or hash tables using spread operator `...` before expressions in table literals. | ||
| 380 | |||
| 381 | ```moonscript | ||
| 382 | parts = | ||
| 383 | * "shoulders" | ||
| 384 | * "knees" | ||
| 385 | lyrics = | ||
| 386 | * "head" | ||
| 387 | * ...parts | ||
| 388 | * "and" | ||
| 389 | * "toes" | ||
| 390 | |||
| 391 | copy = {...other} | ||
| 392 | |||
| 393 | a = {1, 2, 3, x: 1} | ||
| 394 | b = {4, 5, y: 1} | ||
| 395 | merge = {...a, ...b} | ||
| 396 | ``` | ||
| 397 | <YueDisplay> | ||
| 398 | <pre> | ||
| 399 | parts = | ||
| 400 | * "shoulders" | ||
| 401 | * "knees" | ||
| 402 | lyrics = | ||
| 403 | * "head" | ||
| 404 | * ...parts | ||
| 405 | * "and" | ||
| 406 | * "toes" | ||
| 407 | |||
| 408 | copy = {...other} | ||
| 409 | |||
| 410 | a = {1, 2, 3, x: 1} | ||
| 411 | a = {4, 5, y: 1} | ||
| 412 | merge = {...a, ...b} | ||
| 413 | </pre> | ||
| 414 | </YueDisplay> | ||
| 415 | |||
| 377 | ### Metatable | 416 | ### Metatable |
| 378 | 417 | ||
| 379 | The **#** operator can be used as a shortcut for metatable manipulation. | 418 | The **#** 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 | |||
| 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 | |||
| 648 | ## Module | 648 | ## Module |
| 649 | 649 | ||
| 650 | ### Import | 650 | ### Import |
| @@ -1979,9 +1979,30 @@ print func_b! -- prints table object | |||
| 1979 | 1979 | ||
| 1980 | This is done to avoid the needless creation of tables for functions that don’t need to return the results of the loop. | 1980 | This 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 | |||
| 1984 | The repeat loop comes from Lua: | ||
| 1985 | |||
| 1986 | ```moonscript | ||
| 1987 | i = 10 | ||
| 1988 | repeat | ||
| 1989 | print i | ||
| 1990 | i -= 1 | ||
| 1991 | until i == 0 | ||
| 1992 | ``` | ||
| 1993 | <YueDisplay> | ||
| 1994 | <pre> | ||
| 1995 | i = 10 | ||
| 1996 | repeat | ||
| 1997 | print i | ||
| 1998 | i -= 1 | ||
| 1999 | until i == 0 | ||
| 2000 | </pre> | ||
| 2001 | </YueDisplay> | ||
| 2002 | |||
| 1982 | ## While Loop | 2003 | ## While Loop |
| 1983 | 2004 | ||
| 1984 | The while loop also comes in two variations: | 2005 | The while loop also comes in four variations: |
| 1985 | 2006 | ||
| 1986 | ```moonscript | 2007 | ```moonscript |
| 1987 | i = 10 | 2008 | i = 10 |
| @@ -2002,6 +2023,24 @@ while running == true do my_function! | |||
| 2002 | </pre> | 2023 | </pre> |
| 2003 | </YueDisplay> | 2024 | </YueDisplay> |
| 2004 | 2025 | ||
| 2026 | ```moonscript | ||
| 2027 | i = 10 | ||
| 2028 | until i == 0 | ||
| 2029 | print i | ||
| 2030 | i -= 1 | ||
| 2031 | |||
| 2032 | until running == false do my_function! | ||
| 2033 | ``` | ||
| 2034 | <YueDisplay> | ||
| 2035 | <pre> | ||
| 2036 | i = 10 | ||
| 2037 | until i == 0 | ||
| 2038 | print i | ||
| 2039 | i -= 1 | ||
| 2040 | until running == false do my_function! | ||
| 2041 | </pre> | ||
| 2042 | </YueDisplay> | ||
| 2043 | |||
| 2005 | 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. | 2044 | 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. |
| 2006 | 2045 | ||
| 2007 | ## Continue | 2046 | ## Continue |
