|
| 1 | +# Feather Plugins |
| 2 | + |
| 3 | +Feather plugins are any Lua modules that extend the functionality of the debugger. |
| 4 | + |
| 5 | +## Creating a plugin |
| 6 | + |
| 7 | +To create a plugin, you need to create a Lua module that exports a table with the following functions: |
| 8 | + |
| 9 | +- `init(config)`: This function is called when the plugin is initialized. |
| 10 | +- `update(dt, feather)`: This function is called every frame. |
| 11 | +- `onerror(msg, feather)`: This function is called when an error occurs. Errors in this function will close the game abruptly. |
| 12 | +- `handleRequest(request, feather)`: This function is called when a request is received. |
| 13 | +- `finish(feather)`: This function is called when the server is closed. |
| 14 | +- `getConfig()`: This function returns the configuration for the plugin. Sent to the client app. |
| 15 | + |
| 16 | +To help with the implementation, Feather provides the `FeatherPlugin` class, which you can extend to create your plugin. |
| 17 | + |
| 18 | +```lua |
| 19 | +local FeatherPlugin = require("feather.plugins.base") |
| 20 | + |
| 21 | +local MyPlugin = Class({ |
| 22 | + __includes = FeatherPlugin, |
| 23 | +}) |
| 24 | + |
| 25 | +function MyPlugin:init(config) |
| 26 | + -- Do something with the config |
| 27 | +end |
| 28 | + |
| 29 | +function MyPlugin:update(dt, feather) |
| 30 | + -- Do something with the dt and feather |
| 31 | +end |
| 32 | + |
| 33 | +function MyPlugin:onerror(msg, feather) |
| 34 | + -- Do something with the msg and feather |
| 35 | +end |
| 36 | + |
| 37 | +function MyPlugin:handleRequest(request, feather) |
| 38 | + -- Do something with the request and feather |
| 39 | +end |
| 40 | + |
| 41 | +function MyPlugin:finish(feather) |
| 42 | + -- Do something with the feather |
| 43 | +end |
| 44 | + |
| 45 | +function MyPlugin:getConfig() |
| 46 | + -- Return the configuration for the plugin |
| 47 | + return { |
| 48 | + type = "my-plugin", |
| 49 | + color = "#ff0000", |
| 50 | + icon = "my-plugin-icon", |
| 51 | + } |
| 52 | +end |
| 53 | + |
| 54 | +return MyPlugin |
| 55 | +``` |
| 56 | + |
| 57 | +## Registering a plugin |
| 58 | + |
| 59 | +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. |
| 60 | + |
| 61 | +```lua |
| 62 | +local MyPlugin = require("my-plugin") |
| 63 | + |
| 64 | +local plugin = FeatherPluginManager.createPlugin(MyPlugin, "my-plugin", { |
| 65 | + -- Plugin options |
| 66 | +}) |
| 67 | +``` |
| 68 | + |
| 69 | +## Plugin lifecycle |
| 70 | + |
| 71 | +The FeatherPluginManager will handle the lifecycle of the plugin and call the appropriate functions. Here's a breakdown of the plugin lifecycle: |
| 72 | + |
| 73 | +1. **Initialization**: The plugin is initialized with the provided options. |
| 74 | +2. **Request Handling**: The plugin handles requests from the client. |
| 75 | +3. **Update**: The plugin is updated every frame. |
| 76 | +4. **Error Handling**: The plugin handles errors that occur in the game. |
| 77 | +5. **Finish**: The plugin is finished and the game is closed. |
| 78 | + |
| 79 | +## Plugin options |
| 80 | + |
| 81 | +The plugin options are passed to the plugin's constructor. Here's an example of a plugin with options: |
| 82 | + |
| 83 | +```lua |
| 84 | +local MyPlugin = require("my-plugin") |
| 85 | + |
| 86 | +local plugin = FeatherPluginManager.createPlugin(MyPlugin, "my-plugin", { |
| 87 | + option1 = "value1", |
| 88 | + option2 = "value2", |
| 89 | +}) |
| 90 | +``` |
| 91 | + |
| 92 | +### Feather Options |
| 93 | + |
| 94 | +By default, every plugin has the following properties available: |
| 95 | + |
| 96 | +- `self.logger`: A logger that logs messages to the Feather logger. |
| 97 | +- `self.observer`: A logger that logs messages to the Feather observer. |
| 98 | + |
| 99 | +## Plugin configuration |
| 100 | + |
| 101 | +Feather plugins can return configuration that is sent to the client. This configuration is used to display the plugin in the plugins tab. |
| 102 | + |
| 103 | +Here's an example of a plugin with configuration: |
| 104 | + |
| 105 | +```lua |
| 106 | +local MyPlugin = require("my-plugin") |
| 107 | + |
| 108 | +function MyPlugin:getConfig() |
| 109 | + return { |
| 110 | + type = "my-plugin", |
| 111 | + color = "#ff0000", |
| 112 | + icon = "my-plugin-icon", |
| 113 | + } |
| 114 | +end |
| 115 | +``` |
| 116 | + |
| 117 | +## Plugin examples |
| 118 | + |
| 119 | +Here are some examples of Feather plugins: |
| 120 | + |
| 121 | +- [Hump's Signal Plugin](../src-lua/plugins/hump/signal/README.md) |
| 122 | +- [Lua State Machine Plugin](../src-lua/plugins/lua-state-machine/README.md) |
| 123 | + |
| 124 | +## Plugin documentation |
| 125 | + |
| 126 | +Each plugin should have a README file that explains how to use it and provides examples. |
0 commit comments