st.hook — Actions & Filters
Hooks work in both client and server contexts.
Actions (fire-and-forget event hooks)
lua
-- Register an action listener
st.hook.registerAction('myAction', function(arg1, arg2)
-- handle
end, priority) -- priority is optional, default 10 (lower = earlier)
-- Fire all registered listeners for an action
st.hook.doActions('myAction', arg1, arg2)Also available as export:
lua
exports['st_libs']:registerAction('myAction', function(...) end, priority)Filters (value transformation pipeline)
lua
-- Register a filter
st.hook.registerFilter('myFilter', function(value, extraArg)
-- transform value
return modifiedValue
end, priority)
-- Apply all filters to a value
local result = st.hook.applyFilters('myFilter', initialValue, extraArg)Also available as export:
lua
exports['st_libs']:registerFilter('myFilter', function(value) return value end)Hooks registered by a resource are automatically removed when that resource stops.