From a02828b3c1d3582d73e44f36bc34e8d86f9b0295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 13 Jun 2022 23:29:19 +0800 Subject: update runner --- script/vm/runner.lua | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'script/vm/runner.lua') diff --git a/script/vm/runner.lua b/script/vm/runner.lua index 38b0b66c..87630512 100644 --- a/script/vm/runner.lua +++ b/script/vm/runner.lua @@ -72,15 +72,28 @@ function mt:_fastWard(pos, node) self._index = i return obj, node end - if obj.type == 'getlocal' - or obj.type == 'setlocal' then - node = self._callback(obj, node) or node + if obj.type == 'getlocal' then + self._callback(obj, node) + elseif obj.type == 'setlocal' then + local newNode = self._callback(obj, node) + if newNode then + node = newNode:copy() + end else error('unexpected type: ' .. obj.type) end end end +---@param action parser.object +---@param topNode vm.node +function mt:_lookInto(action, topNode) + action = vm.getObjectValue(action) or action + if action.type == 'function' then + self:_launchBlock(action, topNode:copy()) + end +end + ---@param block parser.object ---@param node vm.node function mt:_launchBlock(block, node) @@ -89,16 +102,18 @@ function mt:_launchBlock(block, node) return end for _, action in ipairs(block) do - if action.finish < top.start then + local finish = action.range or action.finish + if finish < top.start then goto CONTINUE end + self:_lookInto(action, topNode) top, topNode = self:_fastWard(action.finish, topNode) if not top then return end ::CONTINUE:: end - self:_fastWard(math.huge, topNode) + self:_fastWard(block.finish, topNode) end ---@param loc parser.object @@ -116,5 +131,5 @@ function vm.launchRunner(loc, callback) return end - self:_launchBlock(guide.getParentBlock(loc), vm.getNode(loc)) + self:_launchBlock(guide.getParentBlock(loc), vm.getNode(loc):copy()) end -- cgit v1.2.3