-
Notifications
You must be signed in to change notification settings - Fork 144
Initial plugin support #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| [package] | ||
| name = "feather_api" | ||
| name = "fapi" | ||
| version = "0.1.0" | ||
| authors = ["caelunshun <caelum12321@gmail.com>"] | ||
| edition = "2018" | ||
|
|
||
| [dependencies] | ||
| fapi-common = { path = "common" } | ||
| fapi-macros = { path = "macros" } | ||
|
|
||
| serde_json = "1.0" | ||
| bstr = "0.2" | ||
| log = "0.4" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| `fapi`, the plugin API used for Feather plugins. | ||
|
|
||
| # Terminology | ||
|
|
||
| "Host" refers to the server executable itself, while "plugin" refers to the plugin dynamic library. | ||
|
|
||
| # Contents | ||
|
|
||
| `common`: types and functions shared between the host and plugin implementation | ||
|
|
||
| `macros`: procedural macros exposed to plugins | ||
|
|
||
| `.`: the high-level plugin API exposed to plugins themselves | ||
|
|
||
| `test-plugins`: test plugin crates |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "fapi-common" | ||
| version = "0.1.0" | ||
| authors = ["caelunshun <caelunshun@gmail.com>"] | ||
| edition = "2018" | ||
|
|
||
| [dependencies] | ||
| serde = { version = "1.0", features = ["derive"] } | ||
| serde_json = "1.0" | ||
| semver = { version = "0.9", features = ["serde"] } | ||
| bstr = "0.2" | ||
| log = "0.4" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| //! Types associated with events. | ||
|
|
||
| /// Unique ID of an event type. | ||
| /// These are allocated opaquely | ||
| /// by the host. No guarantees are made. | ||
| #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
| #[repr(transparent)] | ||
| pub struct EventId(pub u64); | ||
|
|
||
| /// Opaque type representing some avoid. | ||
| /// | ||
| /// Pointers to this type may be casted | ||
| /// to a concrete type, given the user | ||
| /// knows the actual type of the event. | ||
| #[repr(C)] | ||
| pub struct OpaqueEvent { | ||
| _private: [u8; 0], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pub mod event; | ||
| pub mod log; | ||
| pub mod states; | ||
| pub mod system; | ||
| pub mod util; | ||
| pub mod vtable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| use log::Level; | ||
|
|
||
| /// Level of a log message to print. | ||
| #[repr(C)] | ||
| #[derive(Copy, Clone, Debug, PartialEq, Eq)] | ||
| pub enum LogLevel { | ||
| Error, | ||
| Warn, | ||
| Info, | ||
| Debug, | ||
| Trace, | ||
| } | ||
|
|
||
| impl From<log::Level> for LogLevel { | ||
| fn from(level: Level) -> Self { | ||
| match level { | ||
| Level::Debug => LogLevel::Debug, | ||
| Level::Error => LogLevel::Error, | ||
| Level::Info => LogLevel::Info, | ||
| Level::Trace => LogLevel::Trace, | ||
| Level::Warn => LogLevel::Warn, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<LogLevel> for log::Level { | ||
| fn from(level: LogLevel) -> Self { | ||
| match level { | ||
| LogLevel::Error => Level::Error, | ||
| LogLevel::Warn => Level::Warn, | ||
| LogLevel::Info => Level::Info, | ||
| LogLevel::Debug => Level::Debug, | ||
| LogLevel::Trace => Level::Trace, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| //! To implement the API, the host needs | ||
| //! to access its state in host calls. | ||
| //! To do this, it passes pointers to opaque | ||
| //! types which store some data it needs | ||
| //! to execute API requests. | ||
| //! | ||
| //! There are multiple state types used | ||
| //! at different times in a plugin's lifecycle. | ||
|
|
||
| /// The server's state at startup, which the plugin | ||
| /// can use for access to startup functionality such | ||
| /// as the system registry. | ||
| #[repr(C)] | ||
| pub struct StartupState { | ||
| _private: [u8; 0], | ||
| } | ||
|
|
||
| /// The server's state during the execution of a synchronous | ||
| /// task on some region. | ||
| #[repr(C)] | ||
| pub struct GameState { | ||
| _private: [u8; 0], | ||
| } | ||
|
|
||
| /// The server's state potentially outside of the context of a synchronous | ||
| /// region-local task. | ||
| /// | ||
| /// Note that an `AsyncState` can be obtained through a `GameState`. | ||
| #[repr(C)] | ||
| pub struct AsyncState { | ||
| _private: [u8; 0], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| //! Defines types for registering systems and event handlers. | ||
|
|
||
| use crate::event::{EventId, OpaqueEvent}; | ||
| use crate::states::GameState; | ||
|
|
||
| /// Specifies a description of a system. | ||
| #[repr(C)] | ||
| pub struct SystemSpec { | ||
| /// A pointer to the function to run when the system is invoked. | ||
| pub f: fn(*mut GameState), | ||
| } | ||
|
|
||
| /// Specifies a description of an event handler. | ||
| #[repr(C)] | ||
| pub struct HandlerSpec { | ||
| /// The function to invoke when the handler runs. | ||
| /// | ||
| /// The function may assume the `OpaqueEvent` pointer | ||
| /// points to the event type associated with `event`. | ||
| pub f: fn(*mut GameState, *mut OpaqueEvent), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better field name like, |
||
| /// The ID of the event type which is to be handled by `f`. | ||
| pub event: EventId, | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the name to something more descriptive than
f, likerun,invoke, orstep?