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 /spec/inputs/macro_export.yue | |
parent | f8cd1220147d606b7e96f88c12fd0f163fb4e1c5 (diff) | |
download | yuescript-0.23.9.tar.gz yuescript-0.23.9.tar.bz2 yuescript-0.23.9.zip |
add macros generating macros feature.v0.23.9
Diffstat (limited to 'spec/inputs/macro_export.yue')
-rw-r--r-- | spec/inputs/macro_export.yue | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/inputs/macro_export.yue b/spec/inputs/macro_export.yue index eec5848..cc7d459 100644 --- a/spec/inputs/macro_export.yue +++ b/spec/inputs/macro_export.yue | |||
@@ -44,6 +44,24 @@ do | |||
44 | _dst_.#{field} = _src_.#{field} | 44 | _dst_.#{field} = _src_.#{field} |
45 | "}" | 45 | "}" |
46 | 46 | ||
47 | export macro enum = (...) -> | ||
48 | items = {...} | ||
49 | items = [item\gsub('"', '') for item in *items] | ||
50 | itemSet = {item, true for item in *items} | ||
51 | (...) -> | ||
52 | count = select "#", ... | ||
53 | if 1 < count | ||
54 | result = "[" | ||
55 | for i = 1, count | ||
56 | item = select i, ... | ||
57 | error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] | ||
58 | result ..= "\"#{item}\"," | ||
59 | result .. "]" | ||
60 | else | ||
61 | item = select 1, ... | ||
62 | error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item] | ||
63 | "\"#{item}\"" | ||
64 | |||
47 | $ -> | 65 | $ -> |
48 | global debugMode = true | 66 | global debugMode = true |
49 | global debugMacro = true | 67 | global debugMacro = true |