diff options
Diffstat (limited to 'spec/inputs/attrib.mp')
-rw-r--r-- | spec/inputs/attrib.mp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/inputs/attrib.mp b/spec/inputs/attrib.mp new file mode 100644 index 0000000..bc1e67e --- /dev/null +++ b/spec/inputs/attrib.mp | |||
@@ -0,0 +1,40 @@ | |||
1 | do | ||
2 | close a, b = setmetatable {},__close:=> print "closed" | ||
3 | const c, d = 123, 'abc' | ||
4 | |||
5 | close a, b | ||
6 | const c, d | ||
7 | |||
8 | do | ||
9 | close v = if flag | ||
10 | func! | ||
11 | else | ||
12 | setmetatable {},__close:=> | ||
13 | |||
14 | close f = with io.open "file.txt" | ||
15 | \write "Hello" | ||
16 | |||
17 | macro block defer = (item)-> "close _ = #{item}" | ||
18 | macro block defer_f = (func)-> "close _ = setmetatable {},__close:#{func}" | ||
19 | |||
20 | do | ||
21 | $defer with io.open "file.txt" | ||
22 | \write "Hello" | ||
23 | |||
24 | $defer setmetatable {},__close:=> print "second" | ||
25 | |||
26 | $defer_f -> print "first" | ||
27 | |||
28 | _defers = setmetatable {},__close:=> | ||
29 | @[#@]! | ||
30 | @[#@] = nil | ||
31 | |||
32 | macro block defer_i = (item)-> " | ||
33 | _defers[#_defers + 1] = #{item} | ||
34 | close _ = _defers" | ||
35 | |||
36 | do | ||
37 | $defer_i -> print 3 | ||
38 | $defer_i -> print 2 | ||
39 | $defer_i -> print 1 | ||
40 | |||