summaryrefslogtreecommitdiff
path: root/server-beta/src/core/setmethod.lua
diff options
context:
space:
mode:
Diffstat (limited to 'server-beta/src/core/setmethod.lua')
-rw-r--r--server-beta/src/core/setmethod.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/server-beta/src/core/setmethod.lua b/server-beta/src/core/setmethod.lua
new file mode 100644
index 00000000..4140c2d5
--- /dev/null
+++ b/server-beta/src/core/setmethod.lua
@@ -0,0 +1,52 @@
+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.method, 'set')
+ end
+
+ 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