MCPcopy Create free account
hub / github.com/StrataWM/strata / register

Function register

src/bindings.rs:16–52  ·  view source on GitHub ↗
(ctx: lua::Context<'gc>, comp: Rc<RefCell<StrataComp>>)

Source from the content-addressed store, hash-verified

14pub mod input;
15
16pub 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}

Callers 1

init_winitFunction · 0.85

Calls 3

spawnMethod · 0.80
quitMethod · 0.80
moduleFunction · 0.50

Tested by

no test coverage detected