(ctx: lua::Context<'gc>, comp: Rc<RefCell<StrataComp>>)
| 14 | pub mod input; |
| 15 | |
| 16 | pub fn register<'gc>(ctx: lua::Context<'gc>, comp: Rc<RefCell<StrataComp>>) -> anyhow::Result<()> { |
| 17 | let index = lua::Table::new(&ctx); |
| 18 | index.set(ctx, "input", input::module(ctx, comp.clone())?)?; |
| 19 | index.set( |
| 20 | ctx, |
| 21 | "spawn", |
| 22 | lua::Callback::from_fn(&ctx, |ctx, _, mut stack| { |
| 23 | let (cmd, _) = stack.consume::<(lua::String, lua::Value)>(ctx)?; |
| 24 | let _ = Command::new(cmd.to_str()?).spawn()?; |
| 25 | |
| 26 | Ok(lua::CallbackReturn::Return) |
| 27 | }), |
| 28 | )?; |
| 29 | index.set( |
| 30 | ctx, |
| 31 | "quit", |
| 32 | lua::Callback::from_fn(&ctx, |ctx, _, mut stack| { |
| 33 | let comp = stack |
| 34 | .consume::<lua::UserData>(ctx)? |
| 35 | .downcast_static::<Rc<RefCell<StrataComp>>>()?; |
| 36 | |
| 37 | comp.borrow_mut().quit(); |
| 38 | |
| 39 | Ok(lua::CallbackReturn::Return) |
| 40 | }), |
| 41 | )?; |
| 42 | |
| 43 | let strata = lua::UserData::new_static(&ctx, comp.clone()); |
| 44 | |
| 45 | let meta = lua::Table::new(&ctx); |
| 46 | meta.set(ctx, lua::MetaMethod::Index, index)?; |
| 47 | |
| 48 | strata.set_metatable(&ctx, Some(meta)); |
| 49 | ctx.globals().set(ctx, "strata", strata)?; |
| 50 | |
| 51 | Ok(()) |
| 52 | } |
no test coverage detected