summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/matcher/vm.lua38
1 files changed, 35 insertions, 3 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 83c29555..f2b5b47b 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -3,6 +3,38 @@ local library = require 'matcher.library'
local DefaultSource = { start = 0, finish = 0 }
+-- 根据赋值顺序决定遍历顺序的表
+local function orderTable()
+ local t = {}
+ local list = {}
+ local mark = {}
+ return setmetatable(t, {
+ __newindex = function (self, k, v)
+ if not mark[k] then
+ mark[k] = true
+ list[#list+1] = k
+ end
+ rawset(self, k, v)
+ end,
+ __pairs = function (self)
+ local i = 0
+ return function ()
+ while true do
+ i = i + 1
+ local k = list[i]
+ if not k then
+ return nil, nil
+ end
+ local v = t[k]
+ if v ~= nil then
+ return k, v
+ end
+ end
+ end
+ end,
+ })
+end
+
local mt = {}
mt.__index = mt
@@ -186,8 +218,8 @@ function mt:mergeChild(a, b, mark)
if not mark then
mark = {}
end
- local child = a.child or {}
- local other = b.child or {}
+ local child = a.child or orderTable()
+ local other = b.child or orderTable()
a.child = nil
b.child = nil
for k, v in pairs(other) do
@@ -243,7 +275,7 @@ function mt:createField(pValue, name, source)
}
if not pValue.child then
- pValue.child = {}
+ pValue.child = orderTable()
end
pValue.child[name] = field
self:inference(pValue, 'table')