yazi/plugin/src/scope.rs
2023-10-15 09:09:36 +08:00

17 lines
455 B
Rust

use core::Ctx;
pub use mlua::Scope;
use crate::{bindings, GLOBALS, LUA};
pub fn scope<'a>(cx: &'a Ctx, f: impl FnOnce(&Scope<'a, 'a>)) {
_ = LUA.scope(|scope| {
let tbl = LUA.create_table()?;
tbl.set("active", bindings::Active::new(scope, cx).make()?)?;
tbl.set("tabs", bindings::Tabs::new(scope, &cx.manager.tabs).make()?)?;
tbl.set("tasks", bindings::Tasks::new(scope, &cx.tasks).make()?)?;
GLOBALS.set("cx", tbl)?;
Ok(f(scope))
});
}