mirror of
https://github.com/bevyengine/bevy
synced 2024-12-25 12:33:07 +00:00
22 lines
579 B
Rust
22 lines
579 B
Rust
use libloading::{Library, Symbol};
|
|
use std::any::Any;
|
|
use crate::AppBuilder;
|
|
|
|
pub trait AppPlugin: Any + Send + Sync {
|
|
fn build(&self, app: &mut AppBuilder);
|
|
fn name(&self) -> &str {
|
|
std::any::type_name::<Self>()
|
|
}
|
|
}
|
|
|
|
pub type CreateAppPlugin = unsafe fn() -> *mut dyn AppPlugin;
|
|
|
|
pub fn load_plugin(path: &str) -> (Library, Box<dyn AppPlugin>) {
|
|
let lib = Library::new(path).unwrap();
|
|
|
|
unsafe {
|
|
let func: Symbol<CreateAppPlugin> = lib.get(b"_create_plugin").unwrap();
|
|
let plugin = Box::from_raw(func());
|
|
(lib, plugin)
|
|
}
|
|
}
|