feat: new cx.layer API to determine the current UI layer (#2247)

This commit is contained in:
三咲雅 · Misaki Masa 2025-01-26 01:54:18 +08:00 committed by GitHub
parent af9a875512
commit da36cd6ab8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 199 additions and 147 deletions

View file

@ -1,5 +1,6 @@
use ratatui::layout::Rect;
use yazi_core::{completion::Completion, confirm::Confirm, help::Help, input::Input, manager::Manager, notify::Notify, pick::Pick, tab::{Folder, Tab}, tasks::Tasks, which::Which};
use yazi_shared::Layer;
pub struct Ctx {
pub manager: Manager,
@ -39,6 +40,29 @@ impl Ctx {
}
None
}
#[inline]
pub fn layer(&self) -> Layer {
if self.which.visible {
Layer::Which
} else if self.completion.visible {
Layer::Completion
} else if self.help.visible {
Layer::Help
} else if self.confirm.visible {
Layer::Confirm
} else if self.input.visible {
Layer::Input
} else if self.pick.visible {
Layer::Pick
} else if self.active().spot.visible() {
Layer::Spot
} else if self.tasks.visible {
Layer::Tasks
} else {
Layer::Manager
}
}
}
impl Ctx {

View file

@ -0,0 +1,38 @@
use std::ops::Deref;
use mlua::{AnyUserData, IntoLua, MetaMethod, UserData, Value};
use super::Lives;
pub(super) struct Ctx {
inner: *const crate::Ctx,
}
impl Deref for Ctx {
type Target = crate::Ctx;
fn deref(&self) -> &Self::Target { unsafe { &*self.inner } }
}
impl Ctx {
#[inline]
pub(super) fn make(inner: &crate::Ctx) -> mlua::Result<AnyUserData> {
Lives::scoped_userdata(Self { inner })
}
}
impl UserData for Ctx {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
methods.add_meta_method(MetaMethod::Index, |lua, me, key: mlua::String| {
match key.as_bytes().as_ref() {
b"active" => super::Tab::make(me.active())?,
b"tabs" => super::Tabs::make(&me.manager.tabs)?,
b"tasks" => super::Tasks::make(&me.tasks)?,
b"yanked" => super::Yanked::make(&me.manager.yanked)?,
b"layer" => return yazi_plugin::bindings::Layer::from(me.layer()).into_lua(lua),
_ => return Ok(Value::Nil),
}
.into_lua(lua)
});
}
}

View file

@ -27,16 +27,7 @@ impl Lives {
});
LUA.set_named_registry_value("cx", scope.create_any_userdata_ref(cx)?)?;
LUA.globals().raw_set(
"cx",
LUA.create_table_from([
("active", super::Tab::make(cx.active())?),
("tabs", super::Tabs::make(&cx.manager.tabs)?),
("tasks", super::Tasks::make(&cx.tasks)?),
("yanked", super::Yanked::make(&cx.manager.yanked)?),
])?,
)?;
LUA.globals().raw_set("cx", super::Ctx::make(cx)?)?;
f()
});

View file

@ -1,6 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(
preference file files filter finder folder iter lives mode preview selected tab tabs
tasks yanked
);
yazi_macro::mod_flat!(context file files filter finder folder iter lives mode preference preview selected tab tabs tasks yanked);

View file

@ -15,10 +15,8 @@ impl<'a> Router<'a> {
#[inline]
pub(super) fn route(&mut self, key: Key) -> bool {
let cx = &mut self.app.cx;
let layer = cx.layer();
if cx.which.visible {
return cx.which.type_(key);
}
if cx.help.visible && cx.help.type_(&key) {
return true;
}
@ -26,22 +24,14 @@ impl<'a> Router<'a> {
return true;
}
if cx.completion.visible {
self.matches(Layer::Completion, key) || self.matches(Layer::Input, key)
} else if cx.help.visible {
self.matches(Layer::Help, key)
} else if cx.input.visible {
self.matches(Layer::Input, key)
} else if cx.confirm.visible {
self.matches(Layer::Confirm, key)
} else if cx.pick.visible {
self.matches(Layer::Pick, key)
} else if cx.active().spot.visible() {
self.matches(Layer::Spot, key)
} else if cx.tasks.visible {
self.matches(Layer::Tasks, key)
} else {
self.matches(Layer::Manager, key)
use Layer as L;
match layer {
L::App => unreachable!(),
L::Manager | L::Tasks | L::Spot | L::Pick | L::Input | L::Confirm | L::Help => {
self.matches(layer, key)
}
L::Completion => self.matches(L::Completion, key) || self.matches(L::Input, key),
L::Which => cx.which.type_(key),
}
}

View file

@ -1,7 +1,7 @@
Entity = {
_inc = 1000,
_children = {
{ "space", id = 1, order = 1000 },
{ "spacer", id = 1, order = 1000 },
{ "icon", id = 2, order = 2000 },
{ "prefix", id = 3, order = 3000 },
{ "highlights", id = 4, order = 4000 },
@ -12,7 +12,7 @@ Entity = {
function Entity:new(file) return setmetatable({ _file = file }, { __index = self }) end
function Entity:space() return " " end
function Entity:spacer() return " " end
function Entity:icon()
local icon = self._file:icon()

View file

@ -2,13 +2,13 @@ Linemode = {
_inc = 1000,
_children = {
{ "solo", id = 1, order = 1000 },
{ "space", id = 2, order = 2000 },
{ "spacer", id = 2, order = 2000 },
},
}
function Linemode:new(file) return setmetatable({ _file = file }, { __index = self }) end
function Linemode:space() return " " end
function Linemode:spacer() return " " end
function Linemode:solo()
local mode = cx.active.pref.linemode

View file

@ -48,16 +48,25 @@ end
-- Mouse events
function Root:click(event, up)
if tostring(cx.layer) ~= "manager" then
return
end
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
return c and c:click(event, up)
end
function Root:scroll(event, step)
if tostring(cx.layer) ~= "manager" then
return
end
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
return c and c:scroll(event, step)
end
function Root:touch(event, step)
if tostring(cx.layer) ~= "manager" then
return
end
local c = ya.child_at(ui.Rect { x = event.x, y = event.y }, self:reflow())
return c and c:touch(event, step)
end

View file

@ -0,0 +1,14 @@
use mlua::{MetaMethod, UserData};
#[derive(Clone, Copy)]
pub struct Layer(yazi_shared::Layer);
impl From<yazi_shared::Layer> for Layer {
fn from(event: yazi_shared::Layer) -> Self { Self(event) }
}
impl UserData for Layer {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
methods.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.0.to_string()));
}
}

View file

@ -1,3 +1,3 @@
#![allow(clippy::module_inception)]
yazi_macro::mod_flat!(bindings cha chan icon image input mouse permit range window);
yazi_macro::mod_flat!(bindings cha chan icon image input layer mouse permit range window);

View file

@ -0,0 +1,20 @@
use mlua::{IntoLua, Lua, MetaMethod, Table, Value};
pub struct Composer;
impl Composer {
pub fn make<F>(lua: &Lua, cap: usize, f: F) -> mlua::Result<Value>
where
F: Fn(&Lua, &[u8]) -> mlua::Result<Value> + 'static,
{
let index = lua.create_function(move |lua, (ts, key): (Table, mlua::String)| {
let v = f(lua, key.as_bytes().as_ref())?;
ts.raw_set(key, v.clone())?;
Ok(v)
})?;
let tbl = lua.create_table_with_capacity(0, cap)?;
tbl.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
tbl.into_lua(lua)
}
}

View file

@ -1,8 +1,9 @@
use mlua::{IntoLua, Lua, LuaSerdeExt, MetaMethod, SerializeOptions, Table, Value};
use mlua::{IntoLua, Lua, LuaSerdeExt, SerializeOptions, Value};
use yazi_boot::BOOT;
use yazi_config::{MANAGER, PREVIEW, THEME};
use super::Plugin;
use crate::Composer;
pub const SER_OPTS: SerializeOptions =
SerializeOptions::new().serialize_none_to_null(false).serialize_unit_to_null(false);
@ -35,24 +36,19 @@ impl<'a> Config<'a> {
}
pub fn install_plugin(self) -> mlua::Result<Self> {
let index = self.lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
let value = match key.as_bytes().as_ref() {
b"fetchers" => Plugin::fetchers(lua)?,
b"spotter" => Plugin::spotter(lua)?,
b"preloaders" => Plugin::preloaders(lua)?,
b"previewer" => Plugin::previewer(lua)?,
_ => return Ok(Value::Nil),
}
.into_lua(lua)?;
ts.raw_set(key, value.clone())?;
Ok(value)
})?;
let fetcher = self.lua.create_table()?;
fetcher.set_metatable(Some(self.lua.create_table_from([(MetaMethod::Index.name(), index)])?));
self.lua.globals().raw_set("PLUGIN", fetcher)?;
self.lua.globals().raw_set(
"PLUGIN",
Composer::make(self.lua, 5, |lua, name| {
match name {
b"fetchers" => Plugin::fetchers(lua)?,
b"spotter" => Plugin::spotter(lua)?,
b"preloaders" => Plugin::preloaders(lua)?,
b"previewer" => Plugin::previewer(lua)?,
_ => return Ok(Value::Nil),
}
.into_lua(lua)
})?,
)?;
Ok(self)
}
}

View file

@ -1,4 +1,4 @@
use mlua::{Lua, Table, UserData};
use mlua::{Lua, MetaMethod, Table, UserData};
use ratatui::widgets::Borders;
use super::Area;
@ -28,7 +28,7 @@ impl Bar {
("ALL", Borders::ALL.bits()),
])?;
bar.set_metatable(Some(lua.create_table_from([("__call", new)])?));
bar.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(bar)
}

View file

@ -1,4 +1,4 @@
use mlua::{Lua, Table, UserData, Value};
use mlua::{Lua, MetaMethod, Table, UserData, Value};
use ratatui::widgets::{Borders, Widget};
use super::Area;
@ -49,7 +49,7 @@ impl Border {
("QUADRANT_OUTSIDE", QUADRANT_OUTSIDE),
])?;
border.set_metatable(Some(lua.create_table_from([("__call", new)])?));
border.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(border)
}

View file

@ -1,6 +1,6 @@
use std::sync::atomic::{AtomicBool, Ordering};
use mlua::{Lua, Table, UserData};
use mlua::{Lua, MetaMethod, Table, UserData};
use yazi_adapter::ADAPTOR;
use super::Area;
@ -17,7 +17,7 @@ impl Clear {
let new = lua.create_function(|_, (_, area): (Table, Area)| Ok(Clear { area }))?;
let clear = lua.create_table()?;
clear.set_metatable(Some(lua.create_table_from([("__call", new)])?));
clear.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(clear)
}

View file

@ -1,11 +1,12 @@
use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, Table, Value};
use mlua::{AnyUserData, IntoLua, Lua, Table, Value};
use tracing::error;
use super::Renderable;
use crate::Composer;
pub fn compose(lua: &Lua) -> mlua::Result<Table> {
let index = lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
let value = match key.as_bytes().as_ref() {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
Composer::make(lua, 20, |lua, key| {
match key {
b"Bar" => super::Bar::compose(lua)?,
b"Border" => super::Border::compose(lua)?,
b"Clear" => super::Clear::compose(lua)?,
@ -26,16 +27,8 @@ pub fn compose(lua: &Lua) -> mlua::Result<Table> {
b"Text" => super::Text::compose(lua)?,
_ => return Ok(Value::Nil),
}
.into_lua(lua)?;
ts.raw_set(key, value.clone())?;
Ok(value)
})?;
let ui = lua.create_table_with_capacity(0, 20)?;
ui.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
Ok(ui)
.into_lua(lua)
})
}
pub fn render_once<F>(widgets: Table, buf: &mut ratatui::buffer::Buffer, trans: F)

View file

@ -1,4 +1,4 @@
use mlua::{ExternalError, Lua, Table, UserData, UserDataMethods, Value};
use mlua::{ExternalError, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
use ratatui::widgets::Widget;
use super::{Area, Span};
@ -19,7 +19,7 @@ impl Gauge {
let new = lua.create_function(|_, _: Table| Ok(Gauge::default()))?;
let gauge = lua.create_table()?;
gauge.set_metatable(Some(lua.create_table_from([("__call", new)])?));
gauge.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(gauge)
}

View file

@ -1,4 +1,4 @@
use mlua::{AnyUserData, Lua, Table, UserData, UserDataMethods};
use mlua::{AnyUserData, Lua, MetaMethod, Table, UserData, UserDataMethods};
use super::{Constraint, Rect};
@ -17,7 +17,7 @@ impl Layout {
let new = lua.create_function(|_, _: Table| Ok(Self::default()))?;
let layout = lua.create_table_from([("HORIZONTAL", HORIZONTAL), ("VERTICAL", VERTICAL)])?;
layout.set_metatable(Some(lua.create_table_from([("__call", new)])?));
layout.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(layout)
}

View file

@ -1,7 +1,7 @@
use std::mem;
use ansi_to_tui::IntoText;
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, Table, UserData, UserDataMethods, Value};
use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
use unicode_width::UnicodeWidthChar;
use super::Span;
@ -41,7 +41,7 @@ impl Line {
("RIGHT", RIGHT.into_lua(lua)?),
])?;
line.set_metatable(Some(lua.create_table_from([("__call", new)])?));
line.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(line)
}
}

View file

@ -1,4 +1,4 @@
use mlua::{ExternalError, Lua, Table, UserData, Value};
use mlua::{ExternalError, Lua, MetaMethod, Table, UserData, Value};
use ratatui::widgets::Widget;
use super::{Area, Text};
@ -25,7 +25,7 @@ impl List {
})?;
let list = lua.create_table()?;
list.set_metatable(Some(lua.create_table_from([("__call", new)])?));
list.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(list)
}

View file

@ -1,6 +1,6 @@
use std::ops::{Add, AddAssign, Deref};
use mlua::{FromLua, Lua, Table, UserData};
use mlua::{FromLua, Lua, MetaMethod, Table, UserData};
#[derive(Clone, Copy, Default, FromLua)]
pub struct Pad(ratatui::widgets::Padding);
@ -51,7 +51,7 @@ impl Pad {
),
])?;
pad.set_metatable(Some(lua.create_table_from([("__call", new)])?));
pad.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(pad)
}
}

View file

@ -1,6 +1,6 @@
use std::{ops::Deref, str::FromStr};
use mlua::{AnyUserData, ExternalResult, Lua, Table, UserData};
use mlua::{AnyUserData, ExternalResult, Lua, MetaMethod, Table, UserData};
use super::Pad;
@ -50,7 +50,7 @@ impl Pos {
let new = lua.create_function(|_, (_, t): (Table, Table)| Self::try_from(t))?;
let position = lua.create_table()?;
position.set_metatable(Some(lua.create_table_from([("__call", new)])?));
position.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(position)
}

View file

@ -1,6 +1,6 @@
use std::ops::Deref;
use mlua::{FromLua, Lua, Table, UserData};
use mlua::{FromLua, Lua, MetaMethod, Table, UserData};
use super::Pad;
@ -36,7 +36,7 @@ impl Rect {
let rect = lua.create_table_from([("default", Self(ratatui::layout::Rect::default()))])?;
rect.set_metatable(Some(lua.create_table_from([("__call", new)])?));
rect.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(rect)
}

View file

@ -1,4 +1,4 @@
use mlua::{AnyUserData, FromLua, Lua, Table, UserData};
use mlua::{AnyUserData, FromLua, Lua, MetaMethod, Table, UserData};
use super::Cell;
@ -18,7 +18,7 @@ impl Row {
})?;
let row = lua.create_table()?;
row.set_metatable(Some(lua.create_table_from([("__call", new)])?));
row.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(row)
}

View file

@ -1,4 +1,4 @@
use mlua::{ExternalError, FromLua, Lua, Table, UserData, UserDataMethods, Value};
use mlua::{ExternalError, FromLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
use unicode_width::UnicodeWidthChar;
const EXPECTED: &str = "expected a string or Span";
@ -11,7 +11,7 @@ impl Span {
let new = lua.create_function(|_, (_, value): (Table, Value)| Span::try_from(value))?;
let span = lua.create_table()?;
span.set_metatable(Some(lua.create_table_from([("__call", new)])?));
span.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(span)
}

View file

@ -1,6 +1,6 @@
use std::str::FromStr;
use mlua::{AnyUserData, ExternalError, ExternalResult, Lua, Table, UserData, UserDataMethods, Value};
use mlua::{AnyUserData, ExternalError, ExternalResult, Lua, MetaMethod, Table, UserData, UserDataMethods, Value};
use yazi_shared::theme::Color;
#[derive(Clone, Copy, Default)]
@ -11,7 +11,7 @@ impl Style {
let new = lua.create_function(|_, (_, value): (Table, Value)| Self::try_from(value))?;
let style = lua.create_table()?;
style.set_metatable(Some(lua.create_table_from([("__call", new)])?));
style.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(style)
}

View file

@ -1,4 +1,4 @@
use mlua::{AnyUserData, Lua, UserData, Value};
use mlua::{AnyUserData, Lua, MetaMethod, UserData, Value};
use ratatui::widgets::StatefulWidget;
use super::{Area, Row};
@ -36,7 +36,7 @@ impl Table {
})?;
let table = lua.create_table()?;
table.set_metatable(Some(lua.create_table_from([("__call", new)])?));
table.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(table)
}

View file

@ -1,7 +1,7 @@
use std::mem;
use ansi_to_tui::IntoText;
use mlua::{ExternalError, ExternalResult, FromLua, IntoLua, Lua, Table, UserData, Value};
use mlua::{ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
use ratatui::widgets::Widget;
use super::{Area, Line, Span};
@ -48,7 +48,7 @@ impl Text {
("WRAP_TRIM", WRAP_TRIM.into_lua(lua)?),
])?;
text.set_metatable(Some(lua.create_table_from([("__call", new)])?));
text.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
Ok(text)
}

View file

@ -1,13 +1,13 @@
use globset::GlobBuilder;
use mlua::{ExternalError, ExternalResult, Function, IntoLua, IntoLuaMulti, Lua, MetaMethod, Table, Value};
use mlua::{ExternalError, ExternalResult, Function, IntoLua, IntoLuaMulti, Lua, Table, Value};
use tokio::fs;
use yazi_fs::{mounts::PARTITIONS, remove_dir_clean};
use crate::{Error, bindings::{Cast, Cha}, file::File, url::{Url, UrlRef}};
use crate::{Composer, Error, bindings::{Cast, Cha}, file::File, url::{Url, UrlRef}};
pub fn compose(lua: &Lua) -> mlua::Result<Table> {
let index = lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
let value = match key.as_bytes().as_ref() {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
Composer::make(lua, 10, |lua, key| {
match key {
b"cwd" => cwd(lua)?,
b"cha" => cha(lua)?,
b"write" => write(lua)?,
@ -18,16 +18,8 @@ pub fn compose(lua: &Lua) -> mlua::Result<Table> {
b"partitions" => partitions(lua)?,
_ => return Ok(Value::Nil),
}
.into_lua(lua)?;
ts.raw_set(key, value.clone())?;
Ok(value)
})?;
let fs = lua.create_table_with_capacity(0, 10)?;
fs.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
Ok(fs)
.into_lua(lua)
})
}
fn cwd(lua: &Lua) -> mlua::Result<Function> {

View file

@ -4,7 +4,7 @@ mod macros;
yazi_macro::mod_pub!(bindings config elements external file fs isolate loader process pubsub url utils);
yazi_macro::mod_flat!(clipboard error lua runtime);
yazi_macro::mod_flat!(clipboard composer error lua runtime);
pub fn init() -> anyhow::Result<()> {
CLIPBOARD.with(<_>::default);

View file

@ -1,6 +1,6 @@
use std::process::Stdio;
use mlua::{AnyUserData, ExternalError, IntoLuaMulti, Lua, Table, UserData, Value};
use mlua::{AnyUserData, ExternalError, IntoLuaMulti, Lua, MetaMethod, Table, UserData, Value};
use tokio::process::{ChildStderr, ChildStdin, ChildStdout};
use super::{Child, output::Output};
@ -30,7 +30,7 @@ impl Command {
("INHERIT", INHERIT),
])?;
command.set_metatable(Some(lua.create_table_from([("__call", new)])?));
command.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
lua.globals().raw_set("Command", command)
}

View file

@ -1,12 +1,14 @@
#![allow(clippy::module_inception)]
use mlua::{IntoLua, Lua, MetaMethod, Table, Value};
use mlua::{IntoLua, Lua, Value};
use crate::Composer;
yazi_macro::mod_flat!(pubsub);
pub(super) fn compose(lua: &Lua) -> mlua::Result<Table> {
let index = lua.create_function(|lua, (ts, key): (Table, mlua::String)| {
let value = match key.as_bytes().as_ref() {
pub(super) fn compose(lua: &Lua) -> mlua::Result<Value> {
Composer::make(lua, 10, |lua, key| {
match key {
b"pub" => Pubsub::pub_(lua)?,
b"pub_to" => Pubsub::pub_to(lua)?,
b"sub" => Pubsub::sub(lua)?,
@ -15,14 +17,6 @@ pub(super) fn compose(lua: &Lua) -> mlua::Result<Table> {
b"unsub_remote" => Pubsub::unsub_remote(lua)?,
_ => return Ok(Value::Nil),
}
.into_lua(lua)?;
ts.raw_set(key, value.clone())?;
Ok(value)
})?;
let ps = lua.create_table_with_capacity(0, 10)?;
ps.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
Ok(ps)
.into_lua(lua)
})
}

View file

@ -1,10 +1,12 @@
use mlua::{IntoLua, Lua, MetaMethod, Table, Value};
use mlua::{IntoLua, Lua, Value};
use crate::Composer;
pub(super) struct Utils;
pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result<Table> {
let index = lua.create_function(move |lua, (ts, key): (Table, mlua::String)| {
let value = match key.as_bytes().as_ref() {
pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result<Value> {
Composer::make(lua, 40, move |lua, key| {
match key {
// App
b"hide" => Utils::hide(lua)?,
@ -80,14 +82,6 @@ pub fn compose(lua: &Lua, isolate: bool) -> mlua::Result<Table> {
_ => return Ok(Value::Nil),
}
.into_lua(lua)?;
ts.raw_set(key, value.clone())?;
Ok(value)
})?;
let ya = lua.create_table_with_capacity(0, 40)?;
ya.set_metatable(Some(lua.create_table_from([(MetaMethod::Index.name(), index)])?));
Ok(ya)
.into_lua(lua)
})
}