search/
Start typing to search packages!
package_2
hook
By @emdomanus
Roblox
MirroredHook
Hook is a tiny id-based subscriber list for Roblox Luau.
It is built for hot callback lists where returned unbind closures and hash-table callback sets are more overhead than you want.
local Hook = require(path.to.hook)
local stepped = Hook.new<number>()
local id = stepped:add(function(dt)
print(dt)
end)
stepped:fire(1 / 60)
stepped:remove(id)
API
Hook.new()creates a subscriber list.hook:add(callback)returns a numeric id.hook:remove(id)removes a callback and returns whether it existed.hook:fire(...)calls the active callbacks.hook:clear()removes every callback.hook:size()returns the active callback count.hook:has(id)returns whether an id is active.hook:deconstruct()clears the hook.
Removal outside of fire is O(1). Removal during fire is deferred and compacted once the current dispatch finishes, so callbacks can safely unhook themselves or others while the hook is firing.
Package Details
Install command (Click to copy)
Version
0.1.0
License
MIT
Safe for commercial use
Automated license review — not legal advice.
