-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
214 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<nav class="fusiondoc-api-breadcrumbs"> | ||
<span>Memory</span> | ||
<span>Members</span> | ||
<span>innerScope</span> | ||
</nav> | ||
|
||
<h1 class="fusiondoc-api-header" markdown> | ||
<span class="fusiondoc-api-icon" markdown>:octicons-workflow-24:</span> | ||
<span class="fusiondoc-api-name">innerScope</span> | ||
<span class="fusiondoc-api-type"> | ||
-> <a href="../../types/scope">Scope</a><T> | ||
</span> | ||
</h1> | ||
|
||
```Lua | ||
function Fusion.innerScope<T>( | ||
existing: Scope<T> | ||
): Scope<T> | ||
``` | ||
|
||
Returns a blank [scope](../../types/scope) with the same methods as an existing | ||
scope. | ||
|
||
Unlike [deriveScope](../derivescope), the returned scope is an inner scope of | ||
the original scope. It exists until either the user calls `doCleanup` on it, or | ||
the original scope is cleaned up. | ||
|
||
!!! warning "Scopes are not unique" | ||
Fusion can recycle old unused scopes. This helps make scopes more | ||
lightweight, but it also means they don't uniquely belong to any part of | ||
your program. | ||
|
||
As a result, you shouldn't hold on to scopes after they've been cleaned up, | ||
and you shouldn't use them as unique identifiers anywhere. | ||
|
||
----- | ||
|
||
## Parameters | ||
|
||
<h3 markdown> | ||
existing | ||
<span class="fusiondoc-api-type"> | ||
: <a href="../../types/scope">Scope</a><T> | ||
</span> | ||
</h3> | ||
|
||
An existing scope, whose methods should be re-used for the new scope. | ||
|
||
----- | ||
|
||
<h2 markdown> | ||
Returns | ||
<span class="fusiondoc-api-type"> | ||
-> <a href="../../types/scope">Scope</a><T> | ||
</span> | ||
</h2> | ||
|
||
A blank inner scope with the same methods as the existing scope. | ||
|
||
----- | ||
|
||
## Learn More | ||
|
||
- [Scopes tutorial](../../../../tutorials/fundamentals/scopes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--!strict | ||
--!nolint LocalUnused | ||
--!nolint LocalShadow | ||
local task = nil -- Disable usage of Roblox's task scheduler | ||
|
||
--[[ | ||
Derives a new scope that's destroyed exactly once, whether by the user or by | ||
the scope that it's inside of. | ||
]] | ||
local Package = script.Parent.Parent | ||
local Types = require(Package.Types) | ||
local deriveScope = require(Package.Memory.deriveScope) | ||
|
||
local function innerScope<T>( | ||
existing: Types.Scope<T> | ||
): Types.Scope<T> | ||
local new = deriveScope(existing) | ||
table.insert(existing, new) | ||
table.insert( | ||
new, | ||
function() | ||
local index = table.find(existing, new) | ||
if index ~= nil then | ||
table.remove(existing, new) | ||
end | ||
end | ||
) | ||
return new | ||
end | ||
|
||
return innerScope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters