-
Notifications
You must be signed in to change notification settings - Fork 8
Brom Bresenham edited this page Sep 20, 2025
·
7 revisions
use v1=resource_provider_1 [, v2=resource_provider_2, ...]
... # By default, 'use' is implicitly scoped to end of current block
use v1=resource_provider_1 [, v2=resource_provider_2, ...]
... # optional 'endUse' explicitly ends scope of 'use'.
endUse
- At its core ,
useassigns resources to local variables within the scope of theusecommand. - If an assigned variable already exists, its value is preserved and restored at the
endUsecommand. - The resource must implement the Use Protocol, described below.
use will automatically call the following methods on a resource provider:
Writing use v = resource_provider becomes local v = resource_provider.on_use().
Returns the acquired resource to the provider.
- The used resource will be correctly released if there are any returns, escapes, or exceptions thrown within the
usestatements.
use builder = String.pool
builder.print "Hello World!"
println builder
# Equivalent to
local provider = String.pool
local builder = provider.on_use
builder.print "Hello World!"
println builder
provider.on_end_use( builder )