TEST [[ function mt:() end function mt:b() mt:() end ]] TEST [[ function mt:() end function mt:m2() self:() end ]] TEST [[ function mt:m3() mt:() end function mt:() end ]] TEST [[ function mt:m3() self:() end function mt:() end ]] TEST [[ local mt mt.__index = mt function mt:() end local obj = setmetatable({}, mt) obj:() ]] TEST [[ local mt mt.__index = mt function mt:() end local obj = setmetatable({}, mt) obj:() ]] TEST [[ local mt function mt:() end local obj = setmetatable({}, { __index = mt }) obj:() ]] TEST [[ local mt local api function mt:() end setmetatable(api, { __index = mt }) api:() ]] TEST [[ local mt function mt:x() self.() end local obj = setmetatable({}, { __index = mt }) obj. = 1 ]] TEST [[ local mt function mt:x() self.() end local obj = setmetatable({ = 1 }, { __index = mt }) ]] TEST [[ local mt function mt:x() self.a.() end local obj = setmetatable({ a = { = 1, } }, { __index = mt }) ]] TEST [[ local sm = setmetatable local mt mt.__index = mt function mt:() end local obj = sm({}, mt) obj:() ]] -- TODO 更换 meta__index 的实现 -- 表和__index之间不共享child -- 编译完成后进行后处理,如果某个field只有读取操作,则将值链接到meta表中 --TEST [[ --local mt = {} --function mt:() --end -- --local obj = setmetatable({}, {__index = mt}) --function obj:x() --end -- --mt:() --]] -- --TEST [[ --local mt = {} --function mt:x() --end -- --local obj = setmetatable({}, {__index = mt}) --function obj:() --end -- --obj:() --]]