diff options
Diffstat (limited to 'server-beta')
-rw-r--r-- | server-beta/src/core/engineer.lua | 1 | ||||
-rw-r--r-- | server-beta/src/core/field.lua | 3 | ||||
-rw-r--r-- | server-beta/src/core/getglobal.lua | 16 | ||||
-rw-r--r-- | server-beta/src/core/index.lua | 13 | ||||
-rw-r--r-- | server-beta/src/core/local.lua | 31 | ||||
-rw-r--r-- | server-beta/test/definition/method.lua | 9 |
6 files changed, 71 insertions, 2 deletions
diff --git a/server-beta/src/core/engineer.lua b/server-beta/src/core/engineer.lua index 0d55479c..b41412aa 100644 --- a/server-beta/src/core/engineer.lua +++ b/server-beta/src/core/engineer.lua @@ -17,6 +17,7 @@ mt['getglobal'] = require 'core.getglobal' mt['setglobal'] = mt['getglobal'] 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' diff --git a/server-beta/src/core/field.lua b/server-beta/src/core/field.lua index 30613582..95c9954f 100644 --- a/server-beta/src/core/field.lua +++ b/server-beta/src/core/field.lua @@ -24,7 +24,8 @@ end function m:value(source, callback) local parent = source.parent - if parent.type == 'setfield' then + if parent.type == 'setfield' + or parent.type == 'tablefield' then if parent.value then self:eachValue(parent.value, callback) end diff --git a/server-beta/src/core/getglobal.lua b/server-beta/src/core/getglobal.lua index 6853d631..8bf45d39 100644 --- a/server-beta/src/core/getglobal.lua +++ b/server-beta/src/core/getglobal.lua @@ -58,14 +58,30 @@ 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 + used[src] = true local parent = src.parent if key == guide.getKeyName(parent) then self:childRef(parent, callback) 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) + end + end + end) end return m diff --git a/server-beta/src/core/index.lua b/server-beta/src/core/index.lua new file mode 100644 index 00000000..812fca78 --- /dev/null +++ b/server-beta/src/core/index.lua @@ -0,0 +1,13 @@ +local m = {} + +function m:value(source, callback) + local parent = source.parent + if parent.type == 'setindex' + or parent.type == 'tableindex' then + if parent.value then + self:eachValue(parent.value, callback) + end + end +end + +return m diff --git a/server-beta/src/core/local.lua b/server-beta/src/core/local.lua index 33a25899..575a9360 100644 --- a/server-beta/src/core/local.lua +++ b/server-beta/src/core/local.lua @@ -41,21 +41,25 @@ function m:ref(source, callback) end function m:field(source, key, callback) + local used = {} local refs = source.ref if refs then for i = 1, #refs do local ref = refs[i] if ref.type == 'getlocal' then + used[ref] = true local parent = ref.parent if key == guide.getKeyName(parent) then self:childRef(parent, callback) end elseif ref.type == 'getglobal' then - -- _ENV.XXX + used[ref] = true if key == guide.getKeyName(ref) then + -- _ENV.XXX callback(ref, 'get') end elseif ref.type == 'setglobal' then + used[ref] = true -- _ENV.XXX = XXX if key == guide.getKeyName(ref) then callback(ref, 'set') @@ -73,6 +77,31 @@ function m:field(source, key, callback) self:eachField(src, key, callback) end end) + self:eachSpecial(function (name, src) + if name == 'rawset' then + local t, k = self:callArgOf(src.parent) + if used[t] and guide.getKeyName(k) == key then + callback(src.parent, 'set') + end + elseif name == 'rawget' then + local t, k, v = self:callArgOf(src.parent) + if used[t] and guide.getKeyName(k) == key then + callback(src.parent, 'get') + self:eachField(v, key, callback) + end + elseif 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) + end + end + end) end function m:value(source, callback) diff --git a/server-beta/test/definition/method.lua b/server-beta/test/definition/method.lua index 58785fe1..70bd3860 100644 --- a/server-beta/test/definition/method.lua +++ b/server-beta/test/definition/method.lua @@ -51,6 +51,15 @@ obj:<?method1?>() TEST [[ local mt +function mt:<!method1!>() +end + +setmetatable(api, { __index = mt }) +api:<?method1?>() +]] + +TEST [[ +local mt local api function mt:<!method1!>() end |