Builtin Library
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.refis anAssetRef<renderFeature>, a renderFeature identity, or a function answering one; a function is called each time the slot creates or looks the feature up, so anasset.resolveinside it resolves from the module that wrote it.opts.adopt = truemakesensurehold a feature another caller already runs onrefbefore 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 runningrefor creates one; the feature's lifetime is the one its own holders give it.
A Slot is:
slot.handle— theRenderFeatureHandleit 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.prepareruns first;options, when given, answers the options tablerenderer.feature.createtakes. 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