Initial plugin support by caelunshun · Pull Request #213 · feather-rs/feather · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 127 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
8 changes: 7 additions & 1 deletion api/Cargo.toml
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"
15 changes: 15 additions & 0 deletions api/README.md
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
12 changes: 12 additions & 0 deletions api/common/Cargo.toml
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"
18 changes: 18 additions & 0 deletions api/common/src/event.rs
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],
}
6 changes: 6 additions & 0 deletions api/common/src/lib.rs
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;
36 changes: 36 additions & 0 deletions api/common/src/log.rs
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,
}
}
}
32 changes: 32 additions & 0 deletions api/common/src/states.rs
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],
}
23 changes: 23 additions & 0 deletions api/common/src/system.rs
Loading