diff options
author | Li Jin <dragon-fly@qq.com> | 2021-10-12 10:04:44 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2021-10-12 10:04:44 +0800 |
commit | 60a979e224f26117f5be82bfca757a2483cef0fd (patch) | |
tree | 7c6af44f6dcada1f23979b820ba830251997b161 /spec/outputs/metatable.lua | |
parent | a19b242cbaf53721b20a3163dd06f43e9ef2b487 (diff) | |
download | yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.gz yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.tar.bz2 yuescript-60a979e224f26117f5be82bfca757a2483cef0fd.zip |
fix test.
Diffstat (limited to 'spec/outputs/metatable.lua')
-rw-r--r-- | spec/outputs/metatable.lua | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/spec/outputs/metatable.lua b/spec/outputs/metatable.lua new file mode 100644 index 0000000..16ae86c --- /dev/null +++ b/spec/outputs/metatable.lua | |||
@@ -0,0 +1,113 @@ | |||
1 | local a = setmetatable({ | ||
2 | close = true, | ||
3 | }, { | ||
4 | __close = function(self) | ||
5 | return print("out of scope") | ||
6 | end | ||
7 | }) | ||
8 | local b = setmetatable({ }, { | ||
9 | __add = function(left, right) | ||
10 | return right - left | ||
11 | end | ||
12 | }) | ||
13 | local c = setmetatable({ | ||
14 | key1 = true, | ||
15 | key2 = true | ||
16 | }, { | ||
17 | __add = add | ||
18 | }) | ||
19 | local w = setmetatable({ }, { | ||
20 | [name] = 123, | ||
21 | ["new"] = function(self, val) | ||
22 | return { | ||
23 | val | ||
24 | } | ||
25 | end | ||
26 | }) | ||
27 | getmetatable(w)["new"](getmetatable(w)[name]) | ||
28 | local _ <close> = setmetatable({ }, { | ||
29 | __close = function() | ||
30 | return print("out of scope") | ||
31 | end | ||
32 | }) | ||
33 | local d, e = a.close, getmetatable(a).__close | ||
34 | local f = getmetatable(a):__close(1) | ||
35 | getmetatable(a).__add = function(x, y) | ||
36 | return x + y | ||
37 | end | ||
38 | do | ||
39 | local _obj_0 = a | ||
40 | local new = _obj_0.new | ||
41 | local close, closeA | ||
42 | do | ||
43 | local _obj_1 = getmetatable(_obj_0) | ||
44 | close, closeA = _obj_1.__close, _obj_1.__close | ||
45 | end | ||
46 | print(new, close, closeA) | ||
47 | end | ||
48 | do | ||
49 | local x, new, var, close, closeA, num, add, sub | ||
50 | local _obj_0, _obj_1 | ||
51 | x, _obj_0, _obj_1 = 123, a.b.c, func() | ||
52 | new, var = _obj_0.new, _obj_0.var | ||
53 | do | ||
54 | local _obj_2 = getmetatable(_obj_0) | ||
55 | close, closeA = _obj_2.__close, _obj_2.__close | ||
56 | end | ||
57 | num = _obj_1.num | ||
58 | do | ||
59 | local _obj_2 = getmetatable(_obj_1) | ||
60 | add, sub = _obj_2.__add, _obj_2.__sub | ||
61 | end | ||
62 | end | ||
63 | setmetatable(a.b, { }) | ||
64 | x.abc = 123 | ||
65 | setmetatable(func(), mt) | ||
66 | _ = extra | ||
67 | setmetatable(b.c, mt) | ||
68 | a, d, e = 1, "abc" | ||
69 | local is_same = getmetatable(a).__index == getmetatable(a).__index | ||
70 | setmetatable(a, { | ||
71 | __index = tb | ||
72 | }) | ||
73 | getmetatable(a).__index = tb | ||
74 | getmetatable(a).__index = tb | ||
75 | local mt = getmetatable(a) | ||
76 | tb:func(#list) | ||
77 | getmetatable(tb):__func(list) | ||
78 | getmetatable(tb):__func(list) | ||
79 | local index, setFunc | ||
80 | do | ||
81 | local _obj_0 = getmetatable(require("module")) | ||
82 | index, setFunc = _obj_0.__index, _obj_0.__newindex | ||
83 | end | ||
84 | do | ||
85 | local _with_0 = tb | ||
86 | print(getmetatable(_with_0).__add, getmetatable(_with_0.x):__index("key")) | ||
87 | a = getmetatable(getmetatable(getmetatable(_with_0).__index).__add):__new(123) | ||
88 | b = t(#getmetatable(_with_0).__close.test) | ||
89 | c = t(#getmetatable(_with_0).__close(_with_0.test)) | ||
90 | end | ||
91 | mt = getmetatable(a) | ||
92 | a = setmetatable({ }, mt) | ||
93 | a = setmetatable({ }, { | ||
94 | __index = mt | ||
95 | }) | ||
96 | local index | ||
97 | index = getmetatable(a).__index | ||
98 | index = getmetatable(a).__index | ||
99 | do | ||
100 | local ctor, update | ||
101 | do | ||
102 | local _obj_0 = getmetatable(a) | ||
103 | ctor, update = _obj_0.new, _obj_0.update | ||
104 | end | ||
105 | end | ||
106 | do | ||
107 | local ctor, update | ||
108 | do | ||
109 | local _obj_0 = getmetatable(a) | ||
110 | ctor, update = _obj_0.new, _obj_0.update | ||
111 | end | ||
112 | end | ||
113 | return nil | ||