summaryrefslogtreecommitdiff
path: root/server/test/definition/method.lua
blob: 7db4b56dafe72fae0e5188a1be1874b4d4a26a7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
TEST [[
function mt:<!a!>()
end
function mt:b()
    mt:<?a?>()
end
]]

TEST [[
function mt:<!m1!>()
end
function mt:m2()
    self:<?m1?>()
end
]]

TEST [[
function mt:m3()
    mt:<?m4?>()
end
function mt:<!m4!>()
end
]]

TEST [[
function mt:m3()
    self:<?m4?>()
end
function mt:<!m4!>()
end
]]

TEST [[
local mt
mt.__index = mt
function mt:<!method1!>()
end

local obj = setmetatable({}, mt)
obj:<?method1?>()
]]

TEST [[
local mt
mt.__index = mt
function mt:<!method1!>()
end

local obj = setmetatable({}, mt)
obj:<?method1?>()
]]

TEST [[
local mt
function mt:<!method1!>()
end

local obj = setmetatable({}, { __index = mt })
obj:<?method1?>()
]]

TEST [[
local mt
local api
function mt:<!method1!>()
end

setmetatable(api, { __index = mt })
api:<?method1?>()
]]

TEST [[
local mt
function mt:x()
    self.<?init?>()
end

local obj = setmetatable({}, { __index = mt })
obj.<!init!> = 1
]]

TEST [[
local mt
function mt:x()
    self.<?init?>()
end

local obj = setmetatable({ <!init!> = 1 }, { __index = mt })
]]

TEST [[
local mt
function mt:x()
    self.a.<?out?>()
end

local obj = setmetatable({
    a = {
        <!out!> = 1,
    }
}, { __index = mt })
]]

TEST [[
local sm = setmetatable
local mt
mt.__index = mt
function mt:<!method1!>()
end

local obj = sm({}, mt)
obj:<?method1?>()
]]

-- TODO 更换 meta__index 的实现
-- 表和__index之间不共享child
-- 编译完成后进行后处理,如果某个field只有读取操作,则将值链接到meta表中

--TEST [[
--local mt = {}
--function mt:<!x!>()
--end
--
--local obj = setmetatable({}, {__index = mt})
--function obj:x()
--end
--
--mt:<?x?>()
--]]
--
--TEST [[
--local mt = {}
--function mt:x()
--end
--
--local obj = setmetatable({}, {__index = mt})
--function obj:<!x!>()
--end
--
--obj:<?x?>()
--]]