Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit5e96992b1b

README.md

featureSlot

The render feature a module turns on and off. A slot holds the handle of the feature it started, starts it again whenever it is not live, and destroys it on demand, so a module that switches an effect with its settings writes the switch and nothing else.

Exports

  • FeatureSlot.new(ref, opts?) -> Slot — a slot for one feature. ref is an AssetRef<renderFeature>, a renderFeature identity, or a function answering one; a function is called each time the slot creates or looks the feature up, so an asset.resolve inside it resolves from the module that wrote it. opts.adopt = true makes ensure hold a feature another caller already runs on ref before creating one.
  • FeatureSlot.shared(ref) -> SharedSlot — a slot for a feature several callers share, holding only its guid. shared.ensure() answers at once while that guid names a live feature, and otherwise takes the guid of a feature already running ref or creates one; the feature's lifetime is the one its own holders give it.

A Slot is:

  • slot.handle — the RenderFeatureHandle it holds, or nil.
  • slot.live() -> boolean — whether the handle names a live feature.
  • slot.ensure(prepare?, options?) -> boolean — start the feature when it is not live. prepare runs first; options, when given, answers the options table renderer.feature.create takes. True when it started or adopted one.
  • slot.drop() -> boolean — destroy the held feature and clear the handle. True when it held one.

Usage

local FeatureSlot = require("@builtin::modules.featureSlot")

local feature = FeatureSlot.new(function()
    return asset.resolve("shutterBlur", "renderFeature")
end)

local function apply(strength: number)
    if strength > 0 then
        feature.ensure(pushParams)
    else
        feature.drop()
    end
end