diff options
| author | Allie <13716824+ChildishGiant@users.noreply.github.com> | 2022-04-12 06:33:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-12 13:33:02 +0800 |
| commit | e6567c0d290fc76a5919dae4c57d3550eb2541b8 (patch) | |
| tree | ce933871fb8d23a6aab92b217b66640374ae5bc6 /doc/docs | |
| parent | 911204c19378ef943c8daec5205fd60caa523321 (diff) | |
| download | yuescript-e6567c0d290fc76a5919dae4c57d3550eb2541b8.tar.gz yuescript-e6567c0d290fc76a5919dae4c57d3550eb2541b8.tar.bz2 yuescript-e6567c0d290fc76a5919dae4c57d3550eb2541b8.zip | |
Add docs for += -= and []= (#90)
* add OpenGraph data
* add docs for syntactic sugar
Diffstat (limited to 'doc/docs')
| -rwxr-xr-x | doc/docs/doc/README.md | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index be83be3..fcd7bba 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
| @@ -118,14 +118,14 @@ export yuescript = "ζδΉθζ¬" | |||
| 118 | 118 | ||
| 119 |  Use Yuescript module in Lua: | 119 |  Use Yuescript module in Lua: |
| 120 | 120 | ||
| 121 | * **Case 1** | 121 | * **Case 1** |
| 122 | Require "your_yuescript_entry.yue" in Lua. | 122 | Require "your_yuescript_entry.yue" in Lua. |
| 123 | ```Lua | 123 | ```Lua |
| 124 | require("yue")("your_yuescript_entry") | 124 | require("yue")("your_yuescript_entry") |
| 125 | ``` | 125 | ``` |
| 126 |  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 |  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** |
| 129 | Require Yuescript module and rewite message by hand. | 129 | Require Yuescript module and rewite message by hand. |
| 130 | ```lua | 130 | ```lua |
| 131 | local yue = require("yue") | 131 | local yue = require("yue") |
| @@ -136,7 +136,7 @@ end, function(err) | |||
| 136 | end) | 136 | end) |
| 137 | ``` | 137 | ``` |
| 138 | 138 | ||
| 139 | * **Case 3** | 139 | * **Case 3** |
| 140 | Use the Yuescript compiler function in Lua. | 140 | Use the Yuescript compiler function in Lua. |
| 141 | ```lua | 141 | ```lua |
| 142 | local yue = require("yue") | 142 | local 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 |   Use cases: | 177 |   Use cases: |
| 178 |   Recursively compile every Yuescript file with extension **.yue** under current path: **yue .** | 178 |   Recursively compile every Yuescript file with extension **.yue** under current path: **yue .** |
| 179 |   Compile and save results to a target path: **yue -t /target/path/ .** | 179 |   Compile and save results to a target path: **yue -t /target/path/ .** |
| 180 |   Compile and reserve debug info: **yue -l .** | 180 |   Compile and reserve debug info: **yue -l .** |
| 181 |   Compile and generate minified codes: **yue -m .** | 181 |   Compile and generate minified codes: **yue -m .** |
| 182 |   Execute raw codes: **yue -e 'print 123'** | 182 |   Execute raw codes: **yue -e 'print 123'** |
| 183 |   Execute a Yuescript file: **yue -e main.yue** | 183 |   Execute a Yuescript file: **yue -e main.yue** |
| 184 | 184 | ||
| 185 | ## Macro | 185 | ## Macro |
| @@ -360,11 +360,42 @@ tb::func! if tb != nil | |||
| 360 | </pre> | 360 | </pre> |
| 361 | </YueDisplay> | 361 | </YueDisplay> |
| 362 | 362 | ||
| 363 | ### Incrementing and Decrementing | ||
| 364 | |||
| 365 | Yuescript adds the **+=** operator for incrementing and **-=** operator for decrementing values. | ||
| 366 | |||
| 367 | ```moonscript | ||
| 368 | i = 0 | ||
| 369 | i += 1 | ||
| 370 | i -= 1 | ||
| 371 | ``` | ||
| 372 | <YueDisplay> | ||
| 373 | <pre> | ||
| 374 | i = 0 | ||
| 375 | i += 1 | ||
| 376 | i -= 1 | ||
| 377 | </pre> | ||
| 378 | </YueDisplay> | ||
| 379 | |||
| 380 | ### Appending to tables | ||
| 381 | The **[] =** operator is used to append values to tables. | ||
| 382 | |||
| 383 | ```moonscript | ||
| 384 | table = {} | ||
| 385 | table[] = "Value" | ||
| 386 | ``` | ||
| 387 | <YueDisplay> | ||
| 388 | <pre> | ||
| 389 | table = {} | ||
| 390 | table[] = "Value" | ||
| 391 | </pre> | ||
| 392 | </YueDisplay> | ||
| 393 | |||
| 363 | ### Metatable | 394 | ### Metatable |
| 364 | 395 | ||
| 365 | The **#** operator can be used as a shortcut for metatable manipulation. | 396 | The **#** operator can be used as a shortcut for metatable manipulation. |
| 366 | 397 | ||
| 367 | * **Metatable Creation** | 398 | * **Metatable Creation** |
| 368 | Create normal table with key **#** or metamethod key that ends with **#**. | 399 | Create normal table with key **#** or metamethod key that ends with **#**. |
| 369 | 400 | ||
| 370 | ```moonscript | 401 | ```moonscript |
| @@ -400,7 +431,7 @@ close _ = close#: -> print "out of scope" | |||
| 400 | </pre> | 431 | </pre> |
| 401 | </YueDisplay> | 432 | </YueDisplay> |
| 402 | 433 | ||
| 403 | * **Metatable Accessing** | 434 | * **Metatable Accessing** |
| 404 | Accessing metatable with key **#** or metamethod key that ends with **#**. | 435 | Accessing metatable with key **#** or metamethod key that ends with **#**. |
| 405 | 436 | ||
| 406 | ```moonscript | 437 | ```moonscript |
| @@ -423,7 +454,7 @@ print tb.item | |||
| 423 | </pre> | 454 | </pre> |
| 424 | </YueDisplay> | 455 | </YueDisplay> |
| 425 | 456 | ||
| 426 | * **Metatable Destructure** | 457 | * **Metatable Destructure** |
| 427 | Destruct metatable with metamethod key that ends with **#**. | 458 | Destruct metatable with metamethod key that ends with **#**. |
| 428 | 459 | ||
| 429 | ```moonscript | 460 | ```moonscript |
| @@ -643,7 +674,7 @@ do | |||
| 643 | 674 | ||
| 644 | The export statement offers a concise way to define modules. | 675 | The export statement offers a concise way to define modules. |
| 645 | 676 | ||
| 646 | * **Named Export** | 677 | * **Named Export** |
| 647 | Named export will define a local variable as well as adding a field in the exported table. | 678 | Named export will define a local variable as well as adding a field in the exported table. |
| 648 | 679 | ||
| 649 | ```moonscript | 680 | ```moonscript |
| @@ -679,7 +710,7 @@ export class Something | |||
| 679 | </pre> | 710 | </pre> |
| 680 | </YueDisplay> | 711 | </YueDisplay> |
| 681 | 712 | ||
| 682 | * **Unnamed Export** | 713 | * **Unnamed Export** |
| 683 | Unnamed export will add the target item into the array part of the exported table. | 714 | Unnamed export will add the target item into the array part of the exported table. |
| 684 | 715 | ||
| 685 | ```moonscript | 716 | ```moonscript |
| @@ -709,7 +740,7 @@ export with tmp | |||
| 709 | </pre> | 740 | </pre> |
| 710 | </YueDisplay> | 741 | </YueDisplay> |
| 711 | 742 | ||
| 712 | * **Default Export** | 743 | * **Default Export** |
| 713 | Using the **default** keyword in export statement to replace the exported table with any thing. | 744 | Using the **default** keyword in export statement to replace the exported table with any thing. |
| 714 | 745 | ||
| 715 | ```moonscript | 746 | ```moonscript |
