aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/attrib.mp
diff options
context:
space:
mode:
Diffstat (limited to 'spec/inputs/attrib.mp')
-rw-r--r--spec/inputs/attrib.mp40
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 @@
1do
2 close a, b = setmetatable {},__close:=> print "closed"
3 const c, d = 123, 'abc'
4
5 close a, b
6 const c, d
7
8do
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
17macro block defer = (item)-> "close _ = #{item}"
18macro block defer_f = (func)-> "close _ = setmetatable {},__close:#{func}"
19
20do
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
32macro block defer_i = (item)-> "
33_defers[#_defers + 1] = #{item}
34close _ = _defers"
35
36do
37 $defer_i -> print 3
38 $defer_i -> print 2
39 $defer_i -> print 1
40