Proposal and Disscussion of a Plugin System #259
Replies: 4 comments 5 replies
-
I like the idea of using a zip file for the plugin. However, I think we should use a different file extension from |
Beta Was this translation helpful? Give feedback.
-
I also found a thread on the discord mentioning the planned usage of extism. I plan on looking into it to evaluate how suitable this is with the here proposed plans. |
Beta Was this translation helpful? Give feedback.
-
Forking now to start some work |
Beta Was this translation helpful? Give feedback.
-
Further discussion is happening primaraly at #269 |
Beta Was this translation helpful? Give feedback.
-
Hi everybody, I recently came across this project and really liked the approach. I spend the last few days thinking about a potential Plugin system, including a plugin API, and wanted to discuss my thoughts and define a set of goals such a system should have.
To put one thing first, I would like to also work on a concrete implementation of such system but don't want to decide the design of the system all by myself. Therefore, this discussion.
Requirements (non-exhaustive, only my opinion)
Simple Implementation proposal
I thought of a plugin as an OS independent file that, if placed in the correct folder, will be automatically loaded by the server.
Generally suitable would be a shared library, which is not OS independent. But Rust allows for cross-compilation.
Therefore, I propose a Plugin file similar to a
plugin.jar
will be a zip file (if we want an extra file extension) with the following content:The
plugin.toml
file provides basic configuration for the plugin, which allows the server a save loading of plugins. A sample file could look something like this, with more :Plugin loading
I thought about providing plugin functionality in a separate crate but don't think this is easily achievable because we will run into a circular dependency. The main pumpkin server code needs to call Plugin hooks for events etc. and the plugin crate needs all the types from the pumpkin server such as players etc. And as I can see, functionality is integrated, for example for the player in the main pumpkin crate.
I would propose to moving all module definitions from main.rs into its lib.rs to be able to expose a unique interface.
Create a Plugin module with a plugin manager, which is initialized at startup and manages all plugin related tasks.
On startup, the Plugin Manager looks in a predefined plugins directory and optionally in a by an environment variable defined extra directory (useful for developing plugins). The manager looks for .zip and .pumpkin file that include a valid plugin.toml. If a valid toml is present and the server runs one of the plugins supported platforms. We load the associated library file using the
libloading
crate and load the plugin.Each Plugin must at least contain two things:
This describes a basic loading and initializing of Plugins with a straightforward implementation. I have additional thoughts on event handling and Property exposing and I will write on these topics in a separate post in this discussion so this one doesn't span any longer.
I am looking forward to your thoughts on the topic.
<3 Tim
Beta Was this translation helpful? Give feedback.
All reactions