diff options
author | Li Jin <dragon-fly@qq.com> | 2020-03-23 10:45:24 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-03-23 10:45:24 +0800 |
commit | 14d7e02285857226e26288c1ac83a14eb4fbd478 (patch) | |
tree | be1ee9300a8516b186b1dc8a057f05b17847cabd /spec | |
parent | c4556457629bebbb632dbf4e87a49e2d684697c2 (diff) | |
download | yuescript-14d7e02285857226e26288c1ac83a14eb4fbd478.tar.gz yuescript-14d7e02285857226e26288c1ac83a14eb4fbd478.tar.bz2 yuescript-14d7e02285857226e26288c1ac83a14eb4fbd478.zip |
add support for macro system expanding to Lua codes directly.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/inputs/macro.moon | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/inputs/macro.moon b/spec/inputs/macro.moon index 9083449..47e5a26 100644 --- a/spec/inputs/macro.moon +++ b/spec/inputs/macro.moon | |||
@@ -102,5 +102,38 @@ do | |||
102 | a += $get_inner_hygienic! | 102 | a += $get_inner_hygienic! |
103 | print a | 103 | print a |
104 | 104 | ||
105 | macro lua lua = (codes)-> "#{codes}" | ||
106 | |||
107 | x = 0 | ||
108 | |||
109 | $lua [[ | ||
110 | local function f(a) | ||
111 | return a + 1 | ||
112 | end | ||
113 | x = x + f(3) | ||
114 | ]] | ||
115 | |||
116 | print x | ||
117 | |||
118 | macro lua def = (fname, ...)-> | ||
119 | args = {...} | ||
120 | last = table.remove args | ||
121 | $showMacro "def", "local function #{fname}(#{table.concat args, ', '}) | ||
122 | #{last} | ||
123 | end" | ||
124 | |||
125 | sel = (a, b, c)-> if a then b else c | ||
126 | |||
127 | $def sel, a, b, c, [[ | ||
128 | if a then | ||
129 | return b | ||
130 | else | ||
131 | return c | ||
132 | end | ||
133 | ]] | ||
134 | |||
135 | $def dummy,[[ | ||
136 | ]] | ||
137 | |||
105 | nil | 138 | nil |
106 | 139 | ||