This commit is contained in:
aaron 2023-09-10 21:32:08 +01:00
parent 866135b152
commit e776183452
10 changed files with 480 additions and 367 deletions

View file

@ -1,20 +1,25 @@
if not game then script = require "test/relative-string" end
local create = require(script.Parent.create)
local graph = require(script.Parent.graph)
type Node<T> = graph.Node<T>
local refs = graph.refs
local create_node = graph.create_node
local get_stack_scope = graph.get_stack_scope
local open_scope = graph.open_scope
local close_scope = graph.close_scope
local non_tracking_scope = create_node(false)
local function untrack<T>(source: () -> T): T
local initial = #refs
local scope = get_stack_scope(1)
local value = source()
open_scope(scope or non_tracking_scope)
-- remove any references made since `untrack()` was called
for i = initial, #refs do
refs[i] = nil
end
local v = source()
return value
close_scope()
return v
end
return untrack