8000 use · brombres/Rogue Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Abe Pralle edited this page Sep 7, 2022 · 6 revisions

Syntax

use v1=resource_provider_1 [, v2=resource_provider_2, ...]
  ...
endUse

Description

  • At its core , use assigns resources to local variables within the scope of the use command.
  • If an assigned variable already exists, its value is preserved and restored at the endUse command.
  • The resource must implement the Use Protocol, described below.

Use Protocol

use will automatically call the following methods on a resource provider:

on_use()->SomeType

Writing use v = resource_provider becomes local v = resource_provider.on_use().

on_end_use(v:SomeType)

Returns the acquired resource to the provider.

Description

  • The used resource will be correctly released if there are any returns, escapes, or exceptions thrown within the use statements.

Example

use builder = String.pool
  builder.print "Hello World!"
  println builder
endUse

# Equivalent to
local provider = String.pool
local builder = provider.on_use
builder.print "Hello World!"
println builder
provider.on_end_use( builder )
Clone this wiki locally
0