diff options
author | Li Jin <dragon-fly@qq.com> | 2023-08-07 09:57:27 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-08-07 09:57:27 +0800 |
commit | c9b70274787ed8a77e7b47c4628197f0c6c1ba30 (patch) | |
tree | fae88047d312962aebfd97a0183c2f9f19e2cc76 /spec/inputs | |
parent | aff8e69bf589d2ee5f4a7b72b7e2f643d55b87fa (diff) | |
download | yuescript-c9b70274787ed8a77e7b47c4628197f0c6c1ba30.tar.gz yuescript-c9b70274787ed8a77e7b47c4628197f0c6c1ba30.tar.bz2 yuescript-c9b70274787ed8a77e7b47c4628197f0c6c1ba30.zip |
fixing issue #143 and #144.
Diffstat (limited to 'spec/inputs')
-rw-r--r-- | spec/inputs/attrib.yue | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/spec/inputs/attrib.yue b/spec/inputs/attrib.yue index 500ef0f..fbff75a 100644 --- a/spec/inputs/attrib.yue +++ b/spec/inputs/attrib.yue | |||
@@ -1,3 +1,5 @@ | |||
1 | const a, b, c, d = 1, 2, 3, 4 | ||
2 | |||
1 | do | 3 | do |
2 | close a, b = setmetatable {},__close:=> print "closed" | 4 | close a, b = setmetatable {},__close:=> print "closed" |
3 | const c, d = 123, 'abc' | 5 | const c, d = 123, 'abc' |
@@ -6,6 +8,12 @@ do | |||
6 | const c, d | 8 | const c, d |
7 | 9 | ||
8 | do | 10 | do |
11 | const a, {b, c}, {d} = f!, f1! | ||
12 | |||
13 | do | ||
14 | const a, {b, c}, {d} = f! | ||
15 | |||
16 | do | ||
9 | close v = if flag | 17 | close v = if flag |
10 | func! | 18 | func! |
11 | else | 19 | else |
@@ -22,27 +30,24 @@ do | |||
22 | close d = | 30 | close d = |
23 | :value if a ?? b | 31 | :value if a ?? b |
24 | 32 | ||
25 | macro defer = (item)-> "close _ = #{item}" | ||
26 | macro defer_f = (func)-> "close _ = setmetatable {},__close:#{func}" | ||
27 | |||
28 | do | 33 | do |
29 | $defer with io.open "file.txt" | 34 | close _ = with io.open "file.txt" |
30 | \write "Hello" | 35 | \write "Hello" |
31 | 36 | ||
32 | $defer setmetatable {},__close:=> print "second" | 37 | close _ = <close>: -> print "second" |
33 | 38 | ||
34 | $defer_f -> print "first" | 39 | close _ = <close>: -> print "first" |
35 | 40 | ||
36 | _defers = setmetatable {},__close:=> | 41 | _defers = setmetatable {}, __close: => |
37 | @[#@]! | 42 | @[#@]! |
38 | @[#@] = nil | 43 | @[#@] = nil |
39 | 44 | ||
40 | macro defer_i = (item)-> " | 45 | def = (item)-> |
41 | _defers[#_defers + 1] = #{item} | 46 | _defers[#_defers + 1] = item |
42 | close _ = _defers" | 47 | _defers |
43 | 48 | ||
44 | do | 49 | do |
45 | $defer_i -> print 3 | 50 | close _ = def -> print 3 |
46 | $defer_i -> print 2 | 51 | close _ = def -> print 2 |
47 | $defer_i -> print 1 | 52 | close _ = def -> print 1 |
48 | 53 | ||