diff options
-rw-r--r-- | server-beta/src/core/engineer.lua | 34 | ||||
-rw-r--r-- | server-beta/src/core/field.lua | 7 | ||||
-rw-r--r-- | server-beta/src/core/getfield.lua | 43 | ||||
-rw-r--r-- | server-beta/src/core/getglobal.lua | 54 | ||||
-rw-r--r-- | server-beta/src/core/setfield.lua | 49 | ||||
-rw-r--r-- | server-beta/src/core/tablefield.lua | 9 |
6 files changed, 147 insertions, 49 deletions
diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua index 9171af39..1afdd153 100644 --- a/server-beta/src/core/engineer.lua +++ b/server-beta/src/core/engineer.lua @@ -11,22 +11,24 @@ local mt = {} mt.__index = mt mt.type = 'engineer' -mt['local'] = require 'core.local' -mt['getlocal'] = require 'core.getlocal' -mt['setlocal'] = mt['getlocal'] -mt['getglobal'] = require 'core.getglobal' -mt['setglobal'] = mt['getglobal'] -mt['getfield'] = require 'core.getfield' -mt['field'] = require 'core.field' -mt['method'] = require 'core.method' -mt['index'] = require 'core.index' -mt['number'] = require 'core.number' -mt['boolean'] = require 'core.boolean' -mt['string'] = require 'core.string' -mt['table'] = require 'core.table' -mt['select'] = require 'core.select' -mt['goto'] = require 'core.goto' -mt['label'] = require 'core.label' +mt['local'] = require 'core.local' +mt['getlocal'] = require 'core.getlocal' +mt['setlocal'] = mt['getlocal'] +mt['getglobal'] = require 'core.getglobal' +mt['setglobal'] = mt['getglobal'] +mt['getfield'] = require 'core.getfield' +mt['setfield'] = require 'core.setfield' +mt['tablefield'] = require 'core.tablefield' +mt['field'] = require 'core.field' +mt['method'] = require 'core.method' +mt['index'] = require 'core.index' +mt['number'] = require 'core.number' +mt['boolean'] = require 'core.boolean' +mt['string'] = require 'core.string' +mt['table'] = require 'core.table' +mt['select'] = require 'core.select' +mt['goto'] = require 'core.goto' +mt['label'] = require 'core.label' local specials = { ['_G'] = true, diff --git a/server-beta/src/core/field.lua b/server-beta/src/core/field.lua index 997b38e3..4d48bd93 100644 --- a/server-beta/src/core/field.lua +++ b/server-beta/src/core/field.lua @@ -1,4 +1,5 @@ -local guide = require 'parser.guide' +local guide = require 'parser.guide' +local checkSMT = require 'core.setmetatable' local m = {} @@ -32,6 +33,10 @@ function m:ref(source, callback) end end +function m:field(source, key, callback) + self:eachField(source.parent, key, callback) +end + function m:value(source, callback) local parent = source.parent if parent.type == 'setfield' diff --git a/server-beta/src/core/getfield.lua b/server-beta/src/core/getfield.lua index af16bdf5..328de34a 100644 --- a/server-beta/src/core/getfield.lua +++ b/server-beta/src/core/getfield.lua @@ -5,27 +5,44 @@ local m = {} function m:field(source, key, callback) local used = {} - used[source] = true local found = false + used[source] = true + local node = source.node + used[node] = true + + callback(source.field, 'get') local myKey = guide.getKeyName(source) + self:eachField(node, myKey, 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) + end) + self:eachValue(node, function (src) self:eachField(src, myKey, function (src, mode) - if mode == 'set' then - self:eachValue(src, function (src) - self:eachField(src, key, function (src, mode) - if key == guide.getKeyName(src) then - used[src] = true - callback(src, mode) - if mode == 'set' then - found = true - end - end - end) - end) + 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) end) end) + checkSMT(self, key, used, found, callback) end diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua index d7f56146..2c48ca76 100644 --- a/server-beta/src/core/getglobal.lua +++ b/server-beta/src/core/getglobal.lua @@ -1,4 +1,5 @@ local guide = require 'parser.guide' +local checkSMT = require 'core.setmetatable' local m = {} @@ -57,31 +58,46 @@ function m:ref(source, callback) end function m:field(source, key, callback) - local global = guide.getKeyName(source) local used = {} - self:eachField(source.node, global, function (src, mode) - if mode == 'get' then + 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 + return + end + used[src] = true + self:eachField(src, key, function (src, mode) used[src] = true - local parent = src.parent - if key == guide.getKeyName(parent) then - self:childRef(parent, callback) + if mode == 'set' then + callback(src, mode) + found = true end - end + end) end) - self:eachSpecial(function (name, src) - if name == 'setmetatable' then - local t, mt = self:callArgOf(src.parent) - if used[t] then - self:eachField(mt, 's|__index', function (src, mode) - if mode == 'set' then - self:eachValue(src, function (src) - self:eachField(src, key, callback) - end) - end - end) + + self:eachValue(node, function (src) + self:eachField(src, myKey, function (src, mode) + if used[src] then + return end - 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) + end) end) + + checkSMT(self, key, used, found, callback) end function m:value(source, callback) diff --git a/server-beta/src/core/setfield.lua b/server-beta/src/core/setfield.lua new file mode 100644 index 00000000..bf18842d --- /dev/null +++ b/server-beta/src/core/setfield.lua @@ -0,0 +1,49 @@ +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 + + callback(source.field, 'set') + local myKey = guide.getKeyName(source) + self:eachField(node, myKey, 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) + end) + + self:eachValue(node, function (src) + self:eachField(src, myKey, 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) + end) + end) + + checkSMT(self, key, used, found, callback) +end + +return m diff --git a/server-beta/src/core/tablefield.lua b/server-beta/src/core/tablefield.lua new file mode 100644 index 00000000..a5447e3f --- /dev/null +++ b/server-beta/src/core/tablefield.lua @@ -0,0 +1,9 @@ +local m = {} + +function m:field(source, key, callback) + if source.value then + self:eachField(source.value, key, callback) + end +end + +return m |