TEST [[ _ENV. = 1 print() ]] TEST [[ _G. = 1 print() ]] TEST [[ print() ]] 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 function mt:() end setmetatable(api, { __index = mt }) api:() ]] 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 obj:x() ]] TEST [[ local mt function mt:x() self.() end local obj = setmetatable({ = 1 }, { __index = mt }) obj:x() ]] TEST [[ local mt function mt:x() self.a.() end local obj = setmetatable({ a = { = 1, } }, { __index = mt }) obj:x() ]] TEST [[ local sm = setmetatable local mt mt.__index = mt function mt:() end local obj = sm({}, mt) obj:() ]] -- TODO --TEST [[ --local mt = {} --function mt:() --end -- --local obj = setmetatable({}, {__index = mt}) --function obj:x() --end -- --mt:() --]] -- TODO 通过代码执行顺序来判断 --TEST [[ --local mt = {} --function mt:x() --end -- --local obj = setmetatable({}, {__index = mt}) --function obj:() --end -- --obj:() --]]