summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/service.lua4
-rw-r--r--server/src/vm/value.lua38
2 files changed, 18 insertions, 24 deletions
diff --git a/server/src/service.lua b/server/src/service.lua
index 94c768e8..a7762b8b 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -612,7 +612,7 @@ end
function mt:_testMemory()
local clock = os.clock()
collectgarbage()
- log.debug('collectgarbage: ', os.clock() - clock)
+ log.debug('collectgarbage: ', ('%.3f'):format(os.clock() - clock))
local clock = os.clock()
local cachedVM = 0
@@ -702,7 +702,7 @@ function mt:_testMemory()
totalLocal,
totalValue
))
- log.debug('test memory: ', os.clock() - clock)
+ log.debug('test memory: ', ('%.3f'):format(os.clock() - clock))
end
function mt:onTick()
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)