diff options
| author | Brooks J Rady <b.j.rady@gmail.com> | 2020-11-17 21:40:01 +0000 |
|---|---|---|
| committer | Brooks J Rady <b.j.rady@gmail.com> | 2020-11-17 21:40:01 +0000 |
| commit | 115bc83b8ebf4bf0cc338106d708ffcc9d20d2b5 (patch) | |
| tree | 7dd198a6b2c393efca3dd38ef6bb5b77049e29c0 /src/lib.rs | |
| download | sl0ppij-115bc83b8ebf4bf0cc338106d708ffcc9d20d2b5.tar.gz sl0ppij-115bc83b8ebf4bf0cc338106d708ffcc9d20d2b5.tar.xz sl0ppij-115bc83b8ebf4bf0cc338106d708ffcc9d20d2b5.zip | |
Initial Commit
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000..536504ff --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,43 @@ +mod keys; +mod shim; + +pub use keys::*; +pub use shim::*; + +pub trait MosaicPlugin { + fn init(&mut self); + fn draw(&mut self, rows: usize, cols: usize); + fn handle_key(&mut self, key: KeyEvent); +} + +#[macro_export] +macro_rules! register_plugin { + ($t:ty) => { + use mosaic_plugin::*; + + use std::cell::RefCell; + thread_local! { + static STATE: RefCell<$t> = RefCell::new(Default::default()); + } + + fn main() { + STATE.with(|state| { + state.borrow_mut().init(); + }); + } + + #[no_mangle] + pub fn draw(rows: i32, cols: i32) { + STATE.with(|state| { + state.borrow_mut().draw(rows as usize, cols as usize); + }); + } + + #[no_mangle] + pub fn handle_key() { + STATE.with(|state| { + state.borrow_mut().handle_key(get_key()); + }); + } + }; +} |
