aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/attrib.yue
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2021-02-17 11:22:07 +0800
committerLi Jin <dragon-fly@qq.com>2021-02-17 11:22:07 +0800
commit7066392d1c974065181d95d93274136dcd625d43 (patch)
treecf51eafc2c52cbc12246a306bca172d799193d30 /spec/inputs/attrib.yue
parent90cd12ad9ef465f3e435e1bd034dcfbe4e19d016 (diff)
downloadyuescript-7066392d1c974065181d95d93274136dcd625d43.tar.gz
yuescript-7066392d1c974065181d95d93274136dcd625d43.tar.bz2
yuescript-7066392d1c974065181d95d93274136dcd625d43.zip
stop reusing variables, rename project.
Diffstat (limited to 'spec/inputs/attrib.yue')
-rw-r--r--spec/inputs/attrib.yue40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/inputs/attrib.yue b/spec/inputs/attrib.yue
new file mode 100644
index 0000000..7e9a42c
--- /dev/null
+++ b/spec/inputs/attrib.yue
@@ -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 defer = (item)-> "close _ = #{item}"
18macro 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 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