From 860979b175b3c9092e6d1a5058c523fd46e15696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 17 Oct 2019 21:03:43 +0800 Subject: =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/core/engineer.lua | 10 +++---- server-beta/src/core/getfield.lua | 41 ++++++++++++++++------------ server-beta/src/core/getglobal.lua | 48 ++++++++++++++++---------------- server-beta/src/core/getindex.lua | 48 -------------------------------- server-beta/src/core/getmethod.lua | 48 -------------------------------- server-beta/src/core/setfield.lua | 56 -------------------------------------- server-beta/src/core/setindex.lua | 48 -------------------------------- server-beta/src/core/setmethod.lua | 54 ------------------------------------ 8 files changed, 53 insertions(+), 300 deletions(-) delete mode 100644 server-beta/src/core/getindex.lua delete mode 100644 server-beta/src/core/getmethod.lua delete mode 100644 server-beta/src/core/setfield.lua delete mode 100644 server-beta/src/core/setindex.lua delete mode 100644 server-beta/src/core/setmethod.lua (limited to 'server-beta/src/core') diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua index 0553df9c..7bde9e4e 100644 --- a/server-beta/src/core/engineer.lua +++ b/server-beta/src/core/engineer.lua @@ -17,12 +17,12 @@ mt['setlocal'] = mt['getlocal'] mt['getglobal'] = require 'core.getglobal' mt['setglobal'] = mt['getglobal'] mt['getfield'] = require 'core.getfield' -mt['setfield'] = require 'core.setfield' +mt['setfield'] = mt['getfield'] mt['tablefield'] = require 'core.tablefield' -mt['getmethod'] = require 'core.getmethod' -mt['setmethod'] = require 'core.setmethod' -mt['getindex'] = require 'core.getindex' -mt['setindex'] = require 'core.setindex' +mt['getmethod'] = mt['getfield'] +mt['setmethod'] = mt['getfield'] +mt['getindex'] = mt['getfield'] +mt['setindex'] = mt['getfield'] mt['field'] = require 'core.field' mt['method'] = require 'core.method' mt['index'] = require 'core.index' diff --git a/server-beta/src/core/getfield.lua b/server-beta/src/core/getfield.lua index 03aa7854..60d3d8d4 100644 --- a/server-beta/src/core/getfield.lua +++ b/server-beta/src/core/getfield.lua @@ -9,28 +9,27 @@ function m:field(source, key, callback) used[source] = true local node = source.node - self:eachDef(node, function (src) - used[src] = true - end) + local myKey = guide.getKeyName(node) - local myKey = guide.getKeyName(source) - if key == myKey then - callback(source, 'get') + if myKey == key then + callback(source) end - self:eachField(node, myKey, function (src, mode) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) + self:eachDef(node, function (src) + if myKey ~= key then + return + end + used[src] = true + if node.type == 'setfield' + or node.type == 'setindex' + or node.type == 'setmethod' then + callback(src, 'set') + elseif node.type == 'getfield' + or node.type == 'getindex' + or node.type == 'getmethod' then + callback(src, 'get') + end end) - self:eachValue(node, function (src) self:eachField(src, key, function (src, mode) if used[src] then @@ -47,4 +46,10 @@ function m:field(source, key, callback) checkSMT(self, key, used, found, callback) end +function m:value(source, callback) + if source.value then + self:eachValue(source.value, callback) + end +end + return m diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua index 72d208a5..4b4f4a10 100644 --- a/server-beta/src/core/getglobal.lua +++ b/server-beta/src/core/getglobal.lua @@ -66,38 +66,38 @@ function m:field(source, key, callback) local found = false used[source] = true - local parent = source.parent - self:eachField(parent, key, callback) - local node = source.node - local myKey = guide.getKeyName(source) - self:eachField(node, myKey, function (src, mode) - if used[src] then + local myKey = guide.getKeyName(node) + + if myKey == key then + callback(source) + end + + self:eachDef(node, function (src) + if myKey ~= key then return end used[src] = true - self:eachField(src, key, function (src, mode) - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) + if node.type == 'setfield' + or node.type == 'setindex' + or node.type == 'setmethod' then + callback(src, 'set') + elseif node.type == 'getfield' + or node.type == 'getindex' + or node.type == 'getmethod' then + callback(src, 'get') + end end) - self:eachValue(node, function (src) - self:eachField(src, myKey, function (src, mode) + self:eachField(src, key, function (src, mode) if used[src] then return end used[src] = true - self:eachField(src, key, function (src, mode) - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) + if mode == 'set' then + callback(src, mode) + found = true + end end) end) @@ -105,7 +105,9 @@ function m:field(source, key, callback) end function m:value(source, callback) - callback(source) + if source.value then + self:eachValue(source.value, callback) + end end return m diff --git a/server-beta/src/core/getindex.lua b/server-beta/src/core/getindex.lua deleted file mode 100644 index c0b3e517..00000000 --- a/server-beta/src/core/getindex.lua +++ /dev/null @@ -1,48 +0,0 @@ -local guide = require 'parser.guide' -local checkSMT = require 'core.setmetatable' - -local m = {} - -function m:field(source, key, callback) - local used = {} - local found = false - used[source] = true - - local node = source.node - used[node] = true - - local myKey = guide.getKeyName(source) - if key == myKey then - callback(source, 'get') - end - - self:eachField(node, myKey, function (src, mode) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - self:eachValue(node, function (src) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - checkSMT(self, key, used, found, callback) -end - -return m diff --git a/server-beta/src/core/getmethod.lua b/server-beta/src/core/getmethod.lua deleted file mode 100644 index c0b3e517..00000000 --- a/server-beta/src/core/getmethod.lua +++ /dev/null @@ -1,48 +0,0 @@ -local guide = require 'parser.guide' -local checkSMT = require 'core.setmetatable' - -local m = {} - -function m:field(source, key, callback) - local used = {} - local found = false - used[source] = true - - local node = source.node - used[node] = true - - local myKey = guide.getKeyName(source) - if key == myKey then - callback(source, 'get') - end - - self:eachField(node, myKey, function (src, mode) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - self:eachValue(node, function (src) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - checkSMT(self, key, used, found, callback) -end - -return m diff --git a/server-beta/src/core/setfield.lua b/server-beta/src/core/setfield.lua deleted file mode 100644 index 6f629d55..00000000 --- a/server-beta/src/core/setfield.lua +++ /dev/null @@ -1,56 +0,0 @@ -local guide = require 'parser.guide' -local checkSMT = require 'core.setmetatable' - -local m = {} - -function m:field(source, key, callback) - local used = {} - local found = false - used[source] = true - - local node = source.node - self:eachDef(node, function (src) - used[src] = true - end) - - local myKey = guide.getKeyName(source) - if key == myKey then - callback(source, 'set') - end - - self:eachField(node, myKey, function (src, mode) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - self:eachValue(node, function (src) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - checkSMT(self, key, used, found, callback) -end - -function m:value(source, callback) - if source.value then - self:eachValue(source.value, callback) - end -end - -return m diff --git a/server-beta/src/core/setindex.lua b/server-beta/src/core/setindex.lua deleted file mode 100644 index 0c0913dc..00000000 --- a/server-beta/src/core/setindex.lua +++ /dev/null @@ -1,48 +0,0 @@ -local guide = require 'parser.guide' -local checkSMT = require 'core.setmetatable' - -local m = {} - -function m:field(source, key, callback) - local used = {} - local found = false - used[source] = true - - local node = source.node - used[node] = true - - local myKey = guide.getKeyName(source) - if key == myKey then - callback(source, 'set') - end - - self:eachField(node, myKey, function (src, mode) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - self:eachValue(node, function (src) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - checkSMT(self, key, used, found, callback) -end - -return m diff --git a/server-beta/src/core/setmethod.lua b/server-beta/src/core/setmethod.lua deleted file mode 100644 index 881b5083..00000000 --- a/server-beta/src/core/setmethod.lua +++ /dev/null @@ -1,54 +0,0 @@ -local guide = require 'parser.guide' -local checkSMT = require 'core.setmetatable' - -local m = {} - -function m:field(source, key, callback) - local used = {} - local found = false - used[source] = true - - local node = source.node - used[node] = true - - local myKey = guide.getKeyName(source) - if key == myKey then - callback(source, 'set') - end - - self:eachField(node, myKey, function (src, mode) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - self:eachValue(node, function (src) - self:eachField(src, key, function (src, mode) - if used[src] then - return - end - used[src] = true - if mode == 'set' then - callback(src, mode) - found = true - end - end) - end) - - checkSMT(self, key, used, found, callback) -end - -function m:value(source, callback) - if source.value then - self:eachValue(source.value, callback) - end -end - -return m -- cgit v1.2.3