diff options
Diffstat (limited to 'doc/docs/doc/README.md')
-rwxr-xr-x | doc/docs/doc/README.md | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 811497a..378e0f4 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
@@ -374,6 +374,48 @@ print $LINE -- get number 2 | |||
374 | </pre> | 374 | </pre> |
375 | </YueDisplay> | 375 | </YueDisplay> |
376 | 376 | ||
377 | ### Generating Macros with Macros | ||
378 | |||
379 | In Yuescript, macro functions allow you to generate code at compile time. By nesting macro functions, you can create more complex generation patterns. This feature enables you to define a macro function that generates another macro function, allowing for more dynamic code generation. | ||
380 | |||
381 | ```moonscript | ||
382 | macro Enum = (...) -> | ||
383 | items = {...} | ||
384 | itemSet = {item, true for item in *items} | ||
385 | (item) -> | ||
386 | error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] | ||
387 | "\"#{item}\"" | ||
388 | |||
389 | macro BodyType = $Enum( | ||
390 | Static | ||
391 | Dynamic | ||
392 | Kinematic | ||
393 | ) | ||
394 | |||
395 | print "Valid enum type:", $BodyType Static | ||
396 | -- print "Compilation error with enum type:", $BodyType Unknown | ||
397 | ``` | ||
398 | |||
399 | <YueDisplay> | ||
400 | <pre> | ||
401 | macro Enum = (...) -> | ||
402 | items = {...} | ||
403 | itemSet = {item, true for item in *items} | ||
404 | (item) -> | ||
405 | error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] | ||
406 | "\"#{item}\"" | ||
407 | |||
408 | macro BodyType = $Enum( | ||
409 | Static | ||
410 | Dynamic | ||
411 | Kinematic | ||
412 | ) | ||
413 | |||
414 | print "Valid enum type:", $BodyType Static | ||
415 | -- print "Compilation error with enum type:", $BodyType Unknown | ||
416 | </pre> | ||
417 | </YueDisplay> | ||
418 | |||
377 | ## Operator | 419 | ## Operator |
378 | 420 | ||
379 | All of Lua's binary and unary operators are available. Additionally **!=** is as an alias for **~=**, and either **\\** or **::** can be used to write a chaining function call like `tb\func!` or `tb::func!`. And Yuescipt offers some other special operators to write more expressive codes. | 421 | All of Lua's binary and unary operators are available. Additionally **!=** is as an alias for **~=**, and either **\\** or **::** can be used to write a chaining function call like `tb\func!` or `tb::func!`. And Yuescipt offers some other special operators to write more expressive codes. |