smr/src/lua/hooks.lua

52 lines
1.9 KiB
Lua

--[[
Global functions that smr exposes that can be detoured by addons
]]
local api = {}
-- Called before any request processing. Returning true "traps" the request, and
-- does not continue calling smr logic. Well-behaved addons should check for
-- "true" from the detoured function, and return true immediately if the check
-- succeeds.
api.pre_request = function(req) end
-- Called after smr request processing. Returning true "traps" the request.
-- Well-behaved addons should check for true from the detoured function, and
-- immediately return true if the check succeeds. This will not stop smr from
-- responding to the request, since by this time http_request_response() has
-- already been called.
api.post_request = function(req) end
-- Called during startup of the worker process
-- calling error() in this function will prevent kore from starting.
-- Return value is ignored.
api.worker_init = function() end
-- Called during shutdown of the worker process
-- Failures in this function cause other addon hooks to this function to be skipped.
-- Return value is ignored.
api.worker_shutdown = function() end
-- The following are tables and their options:
-- "buttonspec" - specifies a button to display on the front end, has the fields:
-- .endpoint - the url to go to when the button is pressed
-- .method - the HTTP method to use to call the endpoint
-- .fields - key/value pairs to send as arguments when calling the endpoint
-- These are usually "hidden" fields for a form.
-- .text - The text that displays on the button
-- Called to display configuration as html.
api.get = {
-- returns an array of buttonspec, displayed at the top of a story,
-- only for the logged in owner of a story.
page_owner = function(env) return {} end,
-- returns an array of buttonspec, displayed at the bottom of a story
page_reader = function(env) return {} end,
}
-- Called when the /_api endpoint is accessed
api.call = function() end
return api