diff options
| author | Li Jin <dragon-fly@qq.com> | 2020-10-21 23:44:50 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2020-10-21 23:44:50 +0800 |
| commit | b6725202f4a8cac5f829dac9a72a81f3ff73e787 (patch) | |
| tree | c173accb869b60cba14babc7685284864bc80426 /spec/inputs/macro.mp | |
| parent | 0777356cbe599b3f88bdfa476e3ffa64bb3a3a8c (diff) | |
| download | yuescript-b6725202f4a8cac5f829dac9a72a81f3ff73e787.tar.gz yuescript-b6725202f4a8cac5f829dac9a72a81f3ff73e787.tar.bz2 yuescript-b6725202f4a8cac5f829dac9a72a81f3ff73e787.zip | |
extend macro feature to support compiling Moonscript to other Lua dialect like teal.
add examples for how to write MoonPlus codes that compile to teal.
fix C++ macro to build without MoonPlus macro feature or built-in Lua.
add support for passing arguments from command line to compiler that can be accessed or altered by "require('moonp').options".
Diffstat (limited to 'spec/inputs/macro.mp')
| -rw-r--r-- | spec/inputs/macro.mp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/spec/inputs/macro.mp b/spec/inputs/macro.mp index 103df95..fafa522 100644 --- a/spec/inputs/macro.mp +++ b/spec/inputs/macro.mp | |||
| @@ -1,11 +1,7 @@ | |||
| 1 | macro block init = -> | 1 | $ -> |
| 2 | with require "moonp" | 2 | package.moonpath = "?.mp;./spec/inputs/?.mp" |
| 3 | package.moonpath = "?.mp;./spec/inputs/?.mp" | ||
| 4 | "" | ||
| 5 | 3 | ||
| 6 | $init! | 4 | import "macro-export" as { |
| 7 | |||
| 8 | import "macro_export" as { | ||
| 9 | $, -- import all macros | 5 | $, -- import all macros |
| 10 | $config:$myconfig, -- rename macro $config to $myconfig | 6 | $config:$myconfig, -- rename macro $config to $myconfig |
| 11 | } | 7 | } |
| @@ -125,6 +121,12 @@ end | |||
| 125 | x = x + f(3) | 121 | x = x + f(3) |
| 126 | ]] | 122 | ]] |
| 127 | 123 | ||
| 124 | $lua[[ | ||
| 125 | function tb:func() | ||
| 126 | print(123) | ||
| 127 | end | ||
| 128 | ]] | ||
| 129 | |||
| 128 | print x | 130 | print x |
| 129 | 131 | ||
| 130 | macro lua def = (fname, ...)-> | 132 | macro lua def = (fname, ...)-> |
| @@ -144,8 +146,11 @@ $def sel, a, b, c, [[ | |||
| 144 | end | 146 | end |
| 145 | ]] | 147 | ]] |
| 146 | 148 | ||
| 147 | $def dummy,[[ | 149 | $def dummy,[[]] |
| 148 | ]] | 150 | |
| 151 | macro lua insertComment = (text)-> "-- #{text\match '[\'"](.*)[\'"]'}" | ||
| 152 | |||
| 153 | $insertComment "a comment here" | ||
| 149 | 154 | ||
| 150 | import 'underscore' as _ | 155 | import 'underscore' as _ |
| 151 | 156 | ||
