From 01c4691c6151bcb65793e93ed44a140fd214d17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 29 Mar 2019 14:10:10 +0800 Subject: =?UTF-8?q?=E8=A7=A3=E9=99=A4=20value:getChild=20=E7=9A=84?= =?UTF-8?q?=E9=80=92=E5=BD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/vm/value.lua | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) (limited to 'server/src/vm') diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index 872e96b6..0c0b8029 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -136,6 +136,7 @@ function mt:getLibChild(index) local childs = libraryBuilder.child(lib) return childs[index] end + return nil end function mt:eachLibChild(callback) @@ -149,30 +150,23 @@ function mt:eachLibChild(callback) end end -local function finishGetChild(self, index, source, mark) +function mt:getChild(index, source) self:setType('table', 0.5) - local value = self:rawGet(index) - if value then - return value - end - local method = self:getMetaMethod('__index') - if not method then - local v = self:getLibChild(index) - return v - end - if not mark then - mark = {} - end - if mark[method] then - return nil + local parent = self + local value + -- 最多检查3层 __index + for _ = 1, 3 do + value = parent:rawGet(index) + if value then + break + end + local method = parent:getMetaMethod('__index') + if not method then + value = parent:getLibChild(index) + break + end + parent = method end - mark[method] = true - - return finishGetChild(method, index, source, mark) -end - -function mt:getChild(index, source) - local value = finishGetChild(self, index) if not value then value = create('any', source) self:setChild(index, value) -- cgit v1.2.3