1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
import "macro_todo" as $
import "macro_todo" as {$, :$todo}
export macro config = (debugging = true)->
global debugMode = debugging == "true"
global debugMacro = true
""
export macro showMacro = (name, res)->
if debugMacro then "
do
txt = #{res}
print '[macro ' .. #{name} .. ']'
print txt
txt
"
else
res
export macro asserts = (cond)->
if debugMode
$showMacro "assert", "assert #{cond}"
else
""
export macro assert = (cond)->
if debugMode
$showMacro "assert", "assert #{cond}"
else
"#{cond}"
export macro copy = (src, dst, ...)->
assert(
src != "_src_" and src != "_dst_" and dst != "_src_" and dst != "_dst_"
"copy targets can not be _src_ or _dst_"
)
"
do
local _src_, _dst_
with _dst_ = #{dst}
with _src_ = #{src}
#{table.concat for field in *{...} do "
_dst_.#{field} = _src_.#{field}
"}"
export macro enum = (...) ->
items = {...}
items = [item\gsub('"', '') for item in *items]
itemSet = {item, true for item in *items}
(...) ->
count = select "#", ...
if 1 < count
result = "["
for i = 1, count
item = select i, ...
error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item]
result ..= "\"#{item}\","
result .. "]"
else
item = select 1, ...
error "got \"#{item}\", expecting one of #{table.concat items, ', '}" unless itemSet[item]
"\"#{item}\""
$ ->
global debugMode = true
global debugMacro = true
|