Feather plugins are any Lua modules that extend the functionality of the debugger.
To create a plugin, you need to create a Lua module that exports a table with the following functions:
init(config): This function is called when the plugin is initialized.update(dt, feather): This function is called every frame.onerror(msg, feather): This function is called when an error occurs. Errors in this function will close the game abruptly.handleRequest(request, feather): This function is called when a request is received.handleActionRequest(request, feather): This function is called when an action request is received.handleParamsUpdate(request, feather): This function is called when a params update request is received.finish(feather): This function is called when the server is closed.getConfig(): This function returns the configuration for the plugin. Sent to the client app.
To help with the implementation, Feather provides the FeatherPlugin class, which you can extend to create your plugin.
local FeatherPlugin = require("feather.plugins.base")
local MyPlugin = Class({
__includes = FeatherPlugin,
})
function MyPlugin:init(config)
-- Do something with the config
end
function MyPlugin:update(dt, feather)
-- Do something with the dt and feather
end
function MyPlugin:onerror(msg, feather)
-- Do something with the msg and feather
end
function MyPlugin:handleRequest(request, feather)
-- Do something with the request and feather
end
function MyPlugin:handleActionRequest(request, feather)
--- Do something with the request and feather
end
function MyPlugin:handleParamsUpdate(request, feather)
--- Do something with the request and feather
return {}
end
function MyPlugin:isSupported(version)
-- Return true if the plugin is supported by the current version of teh Plugin API
return version > 0
end
function MyPlugin:finish(feather)
-- Do something with the feather
end
function MyPlugin:getConfig()
-- Return the configuration for the plugin
return {
type = "my-plugin",
color = "#ff0000",
icon = "my-plugin-icon",
}
end
return MyPluginThe FeatherPluginManager will handle the lifecycle of the plugin and call the appropriate functions. Here's a breakdown of the plugin lifecycle:
init(config): This function is called when the plugin is initialized.getConfig(): This function returns the configuration for the plugin when the Feather app is initialized. Sent to the client app.
handleRequest(request, feather): This function is called when a request is received. (GET)handleActionRequest(request, feather): This function is called when an action request is received. (POST)handleParamsUpdate(request, feather): This function is called when a params update request is received. (PUT)
update(dt, feather): This function is called every frame. (Called after the request handling)
onerror(msg, feather): This function is called when an error occurs. Errors in this function will close the game abruptly. No frame is rendered after this function is called.
finish(feather): This function is called when the server is closed.
To register a plugin, you need to create an instance of it and pass it to the FeatherPluginManager. The FeatherPluginManager will handle the lifecycle of the plugin and call the appropriate functions.
local MyPlugin = require("my-plugin")
local plugin = FeatherPluginManager.createPlugin(MyPlugin, "my-plugin", {
-- Plugin options
})The plugin options are passed to the plugin's constructor. Here's an example of a plugin with options:
local MyPlugin = require("my-plugin")
local plugin = FeatherPluginManager.createPlugin(MyPlugin, "my-plugin", {
option1 = "value1",
option2 = "value2",
})By default, every plugin has the following properties available:
self.logger: A logger that logs messages to the Feather logger.self.observer: A logger that logs messages to the Feather observer.
Feather plugins can return configuration that is sent to the client. This configuration is used to display the plugin in the plugins tab.
Here's an example of a plugin with configuration:
local MyPlugin = require("my-plugin")
function MyPlugin:getConfig()
return {
type = "my-plugin",
color = "#ff0000",
icon = "my-plugin-icon",
}
endFeather plugins can also be used to trigger actions from game code at runtime.
local debugger = FeatherDebugger({
debug = true,
plugins = {
FeatherPluginManager.createPlugin(ScreenshotPlugin, "screenshots", {
screenshotDirectory = "screenshots",
fps = 30,
gifDuration = 5,
}),
},
})
function love.keypressed(key)
if key == "f1" then
debugger:action("screenshots", "screenshot", {})
elseif key == "f2" then
debugger:action("screenshots", "gif", { duration = 3, fps = 60 })
end
endHere are some examples of Feather plugins:
Each plugin should have a README file that explains how to use it and provides examples.