mirror of
https://github.com/bevyengine/bevy
synced 2024-12-24 20:13:07 +00:00
20 lines
559 B
Rust
20 lines
559 B
Rust
|
use crate::app::AppBuilder;
|
||
|
use libloading::{Library, Symbol};
|
||
|
use std::any::Any;
|
||
|
|
||
|
pub trait AppPlugin: Any + Send + Sync {
|
||
|
fn build(&self, app_builder: AppBuilder) -> AppBuilder;
|
||
|
fn name(&self) -> &'static str;
|
||
|
}
|
||
|
|
||
|
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)
|
||
|
}
|
||
|
}
|