1pub use std::path::PathBuf;
2pub use slotmap::DefaultKey;
3
4#[macro_export]
6macro_rules! create_script {
7 ($struct_name:ident) => {
8 #[no_mangle]
9 pub extern "Rust" fn create_script() -> Box<dyn Script> {
10 Box::new($struct_name::new())
11 }
12 };
13}
14
15pub enum Event {
17 Key{ code: u32 }
18}
19
20pub trait Script: Send {
22 fn new() -> Self;
24 fn init(&mut self, ctx: &dyn Context) {
26 println!("Script Init");
27 }
28 fn ready(&mut self, ctx: &dyn Context) {
30 println!("Script Ready");
31 }
32 fn update(&mut self, ctx: &dyn Context, delta: f32) {
34 println!("Script Update");
35 }
36 fn event(&mut self, ctx: &dyn Context, event: Event) {
38 println!("Script Event");
39 }
40}
41
42pub trait Context {
44 fn objects(&self) -> &dyn ObjectServer;
46
47 fn log(&self, msg: &str);
49}
50
51pub trait ObjectServer {
53 fn create_root(&self, object_name: String, script_path: Option<PathBuf>) -> Option<DefaultKey>;
56
57 fn create_child(&self, object_name: String, script_path: Option<PathBuf>) -> Option<DefaultKey>;
60
61 fn create_child_for(&self, object_name: String, script_path: Option<PathBuf>, parent_object: DefaultKey) -> Option<DefaultKey>;
64
65 fn remove(&self, object_id: DefaultKey) -> bool;
67
68 fn set_script(&self, object_id: DefaultKey, script_path: PathBuf) -> bool;
70
71 fn remove_script(&self, object_id: DefaultKey) -> bool;
73
74 fn move_to_parent(&self, child_object_id: DefaultKey, new_parent_id: DefaultKey) -> bool;
76
77 fn get_by_id(&self, object_id: DefaultKey) -> Option<DefaultKey>;
78
79 fn get_by_name(&self, object_name: PathBuf) -> Option<DefaultKey>;
80}
81
82pub trait Test {
83 fn test();
84}