mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
The previous system needed to store of the scope and full AST to build a Resumable object, which means that if persisted, updating the resumable script will have no effect. The new system instead uses an anchor token and does not require any information besides the anchor name.
35 lines
613 B
Lua
35 lines
613 B
Lua
local ast = require("ast")
|
|
|
|
local resume_manager
|
|
|
|
local Anchor
|
|
Anchor = ast.abstract.Node {
|
|
type = "anchor",
|
|
|
|
name = nil,
|
|
|
|
init = function(self, name)
|
|
self.name = name
|
|
self._list_anchors_cache = { [name] = true }
|
|
end,
|
|
|
|
_hash = function(self)
|
|
return ("anchor<%q>"):format(self.name)
|
|
end,
|
|
|
|
_format = function(self, ...)
|
|
return "#"..self.name
|
|
end,
|
|
|
|
_eval = function(self, state)
|
|
if self:contains_resume_target(state) then
|
|
resume_manager:set_reached(state)
|
|
end
|
|
return Anchor:new(self.name)
|
|
end
|
|
}
|
|
|
|
package.loaded[...] = Anchor
|
|
resume_manager = require("state.resume_manager")
|
|
|
|
return Anchor
|