diff options
| author | Li Jin <dragon-fly@qq.com> | 2024-08-05 17:20:00 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2024-08-05 17:20:00 +0800 |
| commit | 94edfbc8c7d62d700dfb59334a0ed3beedd49493 (patch) | |
| tree | f695cec8b8873d5a6e763ac94bf3c81fb6ba0be9 /doc/docs/zh | |
| parent | f8cd1220147d606b7e96f88c12fd0f163fb4e1c5 (diff) | |
| download | yuescript-94edfbc8c7d62d700dfb59334a0ed3beedd49493.tar.gz yuescript-94edfbc8c7d62d700dfb59334a0ed3beedd49493.tar.bz2 yuescript-94edfbc8c7d62d700dfb59334a0ed3beedd49493.zip | |
add macros generating macros feature.v0.23.9
Diffstat (limited to 'doc/docs/zh')
| -rwxr-xr-x | doc/docs/zh/doc/README.md | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index 0257dee..90d1820 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md | |||
| @@ -371,6 +371,47 @@ print $LINE -- 获取当前代码行数:2 | |||
| 371 | </pre> | 371 | </pre> |
| 372 | </YueDisplay> | 372 | </YueDisplay> |
| 373 | 373 | ||
| 374 | ### 用宏生成宏 | ||
| 375 | |||
| 376 | 在月之脚本中,宏函数允许你在编译时生成代码。通过嵌套的宏函数,你可以创建更复杂的生成模式。这个特性允许你定义一个宏函数,用它来生成另一个宏函数,从而实现更加动态的代码生成。 | ||
| 377 | |||
| 378 | ```moonscript | ||
| 379 | macro Enum = (...) -> | ||
| 380 | items = {...} | ||
| 381 | itemSet = {item, true for item in *items} | ||
| 382 | (item) -> | ||
| 383 | error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] | ||
| 384 | "\"#{item}\"" | ||
| 385 | |||
| 386 | macro BodyType = $Enum( | ||
| 387 | Static | ||
| 388 | Dynamic | ||
| 389 | Kinematic | ||
| 390 | ) | ||
| 391 | |||
| 392 | print "有效的枚举类型:", $BodyType Static | ||
| 393 | -- print "编译报错的枚举类型:", $BodyType Unknown | ||
| 394 | ``` | ||
| 395 | <YueDisplay> | ||
| 396 | <pre> | ||
| 397 | macro Enum = (...) -> | ||
| 398 | items = {...} | ||
| 399 | itemSet = {item, true for item in *items} | ||
| 400 | (item) -> | ||
| 401 | error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] | ||
| 402 | "\"#{item}\"" | ||
| 403 | |||
| 404 | macro BodyType = $Enum( | ||
| 405 | Static | ||
| 406 | Dynamic | ||
| 407 | Kinematic | ||
| 408 | ) | ||
| 409 | |||
| 410 | print "有效的枚举类型:", $BodyType Static | ||
| 411 | -- print "编译报错的枚举类型:", $BodyType Unknown | ||
| 412 | </pre> | ||
| 413 | </YueDisplay> | ||
| 414 | |||
| 374 | ## 操作符 | 415 | ## 操作符 |
| 375 | 416 | ||
| 376 | Lua的所有二元和一元操作符在月之脚本中都是可用的。此外,**!=** 符号是 **~=** 的别名,而 **\\** 或 **::** 均可用于编写链式函数调用,如写作 `tb\func!` 或 `tb::func!`。此外月之脚本还提供了一些其他特殊的操作符,以编写更具表达力的代码。 | 417 | Lua的所有二元和一元操作符在月之脚本中都是可用的。此外,**!=** 符号是 **~=** 的别名,而 **\\** 或 **::** 均可用于编写链式函数调用,如写作 `tb\func!` 或 `tb::func!`。此外月之脚本还提供了一些其他特殊的操作符,以编写更具表达力的代码。 |
