diff --git a/yazi-fm/src/components/header.rs b/yazi-fm/src/components/header.rs index a71334fc..12dcca5d 100644 --- a/yazi-fm/src/components/header.rs +++ b/yazi-fm/src/components/header.rs @@ -9,7 +9,7 @@ impl Widget for Header { fn render(self, area: ratatui::layout::Rect, buf: &mut Buffer) { let mut f = || { let area = Rect::cast(&LUA, area)?; - let comp: Table = LUA.globals().get("Header")?; + let comp: Table = LUA.globals().raw_get("Header")?; render_widgets(comp.call_method("render", area)?, buf); Ok::<_, anyhow::Error>(()) }; diff --git a/yazi-fm/src/components/manager.rs b/yazi-fm/src/components/manager.rs index cca83e7f..bf4b266b 100644 --- a/yazi-fm/src/components/manager.rs +++ b/yazi-fm/src/components/manager.rs @@ -9,7 +9,7 @@ impl Widget for Manager { fn render(self, area: ratatui::layout::Rect, buf: &mut Buffer) { let mut f = || { let area = Rect::cast(&LUA, area)?; - let comp: Table = LUA.globals().get("Manager")?; + let comp: Table = LUA.globals().raw_get("Manager")?; render_widgets(comp.call_method("render", area)?, buf); Ok::<_, anyhow::Error>(()) }; diff --git a/yazi-fm/src/components/progress.rs b/yazi-fm/src/components/progress.rs index b234d329..ce8d6d50 100644 --- a/yazi-fm/src/components/progress.rs +++ b/yazi-fm/src/components/progress.rs @@ -12,7 +12,7 @@ impl Progress { ) -> Vec> { let mut patches = vec![]; let mut f = || { - let comp: Table = LUA.globals().get("Progress")?; + let comp: Table = LUA.globals().raw_get("Progress")?; for widget in comp.call_method::<_, Vec>("partial_render", ())? { let Some(w) = cast_to_renderable(widget) else { continue; diff --git a/yazi-fm/src/components/status.rs b/yazi-fm/src/components/status.rs index 556f4aab..dc0e3e0a 100644 --- a/yazi-fm/src/components/status.rs +++ b/yazi-fm/src/components/status.rs @@ -9,7 +9,7 @@ impl Widget for Status { fn render(self, area: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) { let mut f = || { let area = Rect::cast(&LUA, area)?; - let comp: Table = LUA.globals().get("Status")?; + let comp: Table = LUA.globals().raw_get("Status")?; render_widgets(comp.call_method("render", area)?, buf); Ok::<_, anyhow::Error>(()) }; diff --git a/yazi-fm/src/lives/lives.rs b/yazi-fm/src/lives/lives.rs index 171ade83..bb7715d1 100644 --- a/yazi-fm/src/lives/lives.rs +++ b/yazi-fm/src/lives/lives.rs @@ -38,7 +38,7 @@ impl Lives { LUA.set_named_registry_value("cx", scope.create_any_userdata_ref(cx)?)?; let globals = LUA.globals(); - globals.set( + globals.raw_set( "cx", LUA.create_table_from([ ("active", super::Tab::make(cx.manager.active())?), diff --git a/yazi-plugin/src/cast.rs b/yazi-plugin/src/cast.rs index ab7d8da8..d426f3d5 100644 --- a/yazi-plugin/src/cast.rs +++ b/yazi-plugin/src/cast.rs @@ -69,7 +69,7 @@ impl<'lua> IntoLua<'lua> for ValueSendable { ValueSendable::Table(t) => { let table = lua.create_table()?; for (k, v) in t { - table.set(k.into_lua(lua)?, v.into_lua(lua)?)?; + table.raw_set(k.into_lua(lua)?, v.into_lua(lua)?)?; } Ok(Value::Table(table)) } diff --git a/yazi-plugin/src/config.rs b/yazi-plugin/src/config.rs index 6f5a5d4c..cad3a119 100644 --- a/yazi-plugin/src/config.rs +++ b/yazi-plugin/src/config.rs @@ -13,22 +13,22 @@ impl<'a> Config<'a> { pub fn new(lua: &'a Lua) -> Self { Self { lua } } pub fn install_boot(self) -> mlua::Result { - self.lua.globals().set("BOOT", self.lua.to_value_with(&*BOOT, OPTIONS)?)?; + self.lua.globals().raw_set("BOOT", self.lua.to_value_with(&*BOOT, OPTIONS)?)?; Ok(self) } pub fn install_manager(self) -> mlua::Result { - self.lua.globals().set("MANAGER", self.lua.to_value_with(&*MANAGER, OPTIONS)?)?; + self.lua.globals().raw_set("MANAGER", self.lua.to_value_with(&*MANAGER, OPTIONS)?)?; Ok(self) } pub fn install_theme(self) -> mlua::Result { - self.lua.globals().set("THEME", self.lua.to_value_with(&*THEME, OPTIONS)?)?; + self.lua.globals().raw_set("THEME", self.lua.to_value_with(&*THEME, OPTIONS)?)?; Ok(self) } pub fn install_preview(self) -> mlua::Result { - self.lua.globals().set("PREVIEW", self.lua.to_value_with(&*PREVIEW, OPTIONS)?)?; + self.lua.globals().raw_set("PREVIEW", self.lua.to_value_with(&*PREVIEW, OPTIONS)?)?; Ok(self) } } diff --git a/yazi-plugin/src/elements/bar.rs b/yazi-plugin/src/elements/bar.rs index 4abd8ffc..b96fb615 100644 --- a/yazi-plugin/src/elements/bar.rs +++ b/yazi-plugin/src/elements/bar.rs @@ -36,7 +36,7 @@ impl Bar { bar.set_metatable(Some(lua.create_table_from([("__call", new)])?)); - ui.set("Bar", bar) + ui.raw_set("Bar", bar) } } diff --git a/yazi-plugin/src/elements/border.rs b/yazi-plugin/src/elements/border.rs index b0596746..a0af5ada 100644 --- a/yazi-plugin/src/elements/border.rs +++ b/yazi-plugin/src/elements/border.rs @@ -49,7 +49,7 @@ impl Border { border.set_metatable(Some(lua.create_table_from([("__call", new)])?)); - ui.set("Border", border) + ui.raw_set("Border", border) } } diff --git a/yazi-plugin/src/elements/constraint.rs b/yazi-plugin/src/elements/constraint.rs index 03c2debc..1f05df28 100644 --- a/yazi-plugin/src/elements/constraint.rs +++ b/yazi-plugin/src/elements/constraint.rs @@ -7,31 +7,31 @@ impl Constraint { pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> { let constraint = lua.create_table()?; - constraint.set( + constraint.raw_set( "Percentage", lua .create_function(|_, n: u16| Ok(Constraint(ratatui::layout::Constraint::Percentage(n))))?, )?; - constraint.set( + constraint.raw_set( "Ratio", lua.create_function(|_, (a, b): (u32, u32)| { Ok(Constraint(ratatui::layout::Constraint::Ratio(a, b))) })?, )?; - constraint.set( + constraint.raw_set( "Length", lua.create_function(|_, n: u16| Ok(Constraint(ratatui::layout::Constraint::Length(n))))?, )?; - constraint.set( + constraint.raw_set( "Max", lua.create_function(|_, n: u16| Ok(Constraint(ratatui::layout::Constraint::Max(n))))?, )?; - constraint.set( + constraint.raw_set( "Min", lua.create_function(|_, n: u16| Ok(Constraint(ratatui::layout::Constraint::Min(n))))?, )?; - ui.set("Constraint", constraint) + ui.raw_set("Constraint", constraint) } } diff --git a/yazi-plugin/src/elements/elements.rs b/yazi-plugin/src/elements/elements.rs index 5db045dc..caa96606 100644 --- a/yazi-plugin/src/elements/elements.rs +++ b/yazi-plugin/src/elements/elements.rs @@ -24,7 +24,7 @@ pub fn pour(lua: &Lua) -> mlua::Result<()> { super::Span::install(lua, &ui)?; super::Style::install(lua, &ui)?; - lua.globals().set("ui", ui) + lua.globals().raw_set("ui", ui) } pub trait Renderable { diff --git a/yazi-plugin/src/elements/gauge.rs b/yazi-plugin/src/elements/gauge.rs index 408b215b..ad3cf505 100644 --- a/yazi-plugin/src/elements/gauge.rs +++ b/yazi-plugin/src/elements/gauge.rs @@ -15,7 +15,7 @@ pub struct Gauge { impl Gauge { pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> { - ui.set( + ui.raw_set( "Gauge", lua.create_function(|_, area: RectRef| Ok(Gauge { area: *area, ..Default::default() }))?, ) diff --git a/yazi-plugin/src/elements/layout.rs b/yazi-plugin/src/elements/layout.rs index 718e5aaa..0d8ac883 100644 --- a/yazi-plugin/src/elements/layout.rs +++ b/yazi-plugin/src/elements/layout.rs @@ -24,7 +24,7 @@ impl Layout { layout.set_metatable(Some(lua.create_table_from([("__call", new)])?)); - ui.set("Layout", layout) + ui.raw_set("Layout", layout) } } diff --git a/yazi-plugin/src/elements/line.rs b/yazi-plugin/src/elements/line.rs index a90e7750..2f1cd968 100644 --- a/yazi-plugin/src/elements/line.rs +++ b/yazi-plugin/src/elements/line.rs @@ -48,7 +48,7 @@ impl Line { line.set_metatable(Some(lua.create_table_from([("__call", new)])?)); - ui.set("Line", line) + ui.raw_set("Line", line) } } diff --git a/yazi-plugin/src/elements/list.rs b/yazi-plugin/src/elements/list.rs index b4b7c0aa..75b91158 100644 --- a/yazi-plugin/src/elements/list.rs +++ b/yazi-plugin/src/elements/list.rs @@ -13,7 +13,7 @@ pub struct List { impl List { pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> { - ui.set( + ui.raw_set( "List", lua.create_function(|_, (area, items): (RectRef, Vec)| { Ok(Self { area: *area, inner: ratatui::widgets::List::new(items) }) @@ -43,7 +43,7 @@ pub struct ListItem { impl ListItem { pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> { - ui.set( + ui.raw_set( "ListItem", lua.create_function(|_, value: Value| { match value { diff --git a/yazi-plugin/src/elements/padding.rs b/yazi-plugin/src/elements/padding.rs index 2eb3b304..e695a558 100644 --- a/yazi-plugin/src/elements/padding.rs +++ b/yazi-plugin/src/elements/padding.rs @@ -58,7 +58,7 @@ impl Padding { padding.set_metatable(Some(lua.create_table_from([("__call", new)])?)); - ui.set("Padding", padding) + ui.raw_set("Padding", padding) } pub fn register(lua: &Lua) -> mlua::Result<()> { diff --git a/yazi-plugin/src/elements/paragraph.rs b/yazi-plugin/src/elements/paragraph.rs index 07b9e818..204507ed 100644 --- a/yazi-plugin/src/elements/paragraph.rs +++ b/yazi-plugin/src/elements/paragraph.rs @@ -52,7 +52,7 @@ impl Paragraph { paragraph.set_metatable(Some(lua.create_table_from([("__call", new)])?)); - ui.set("Paragraph", paragraph) + ui.raw_set("Paragraph", paragraph) } } diff --git a/yazi-plugin/src/elements/rect.rs b/yazi-plugin/src/elements/rect.rs index 5809312d..45d233cf 100644 --- a/yazi-plugin/src/elements/rect.rs +++ b/yazi-plugin/src/elements/rect.rs @@ -11,10 +11,10 @@ impl Rect { pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> { let new = lua.create_function(|lua, (_, args): (Table, Table)| { Rect::cast(lua, ratatui::layout::Rect { - x: args.get("x")?, - y: args.get("y")?, - width: args.get("w")?, - height: args.get("h")?, + x: args.raw_get("x")?, + y: args.raw_get("y")?, + width: args.raw_get("w")?, + height: args.raw_get("h")?, }) })?; @@ -25,7 +25,7 @@ impl Rect { rect.set_metatable(Some(lua.create_table_from([("__call", new)])?)); - ui.set("Rect", rect) + ui.raw_set("Rect", rect) } pub fn register(lua: &Lua) -> mlua::Result<()> { diff --git a/yazi-plugin/src/elements/span.rs b/yazi-plugin/src/elements/span.rs index 3f94efe5..13cac91b 100644 --- a/yazi-plugin/src/elements/span.rs +++ b/yazi-plugin/src/elements/span.rs @@ -8,7 +8,7 @@ pub struct Span(pub(super) ratatui::text::Span<'static>); impl Span { pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> { - ui.set( + ui.raw_set( "Span", lua.create_function(|_, content: mlua::String| { Ok(Self(ratatui::text::Span::raw(content.to_string_lossy().into_owned()))) diff --git a/yazi-plugin/src/elements/style.rs b/yazi-plugin/src/elements/style.rs index fa5c2068..37958bca 100644 --- a/yazi-plugin/src/elements/style.rs +++ b/yazi-plugin/src/elements/style.rs @@ -11,7 +11,7 @@ impl Style { let style = lua.create_table()?; style.set_metatable(Some(lua.create_table_from([("__call", new)])?)); - ui.set("Style", style) + ui.raw_set("Style", style) } } @@ -29,7 +29,7 @@ impl<'a> From> for Style { style.bg = Color::try_from(bg).ok().map(Into::into); } style.add_modifier = - ratatui::style::Modifier::from_bits_truncate(value.get("modifier").unwrap_or_default()); + ratatui::style::Modifier::from_bits_truncate(value.raw_get("modifier").unwrap_or_default()); Self(style) } } diff --git a/yazi-plugin/src/fs/fs.rs b/yazi-plugin/src/fs/fs.rs index 4d0f1c25..9e920240 100644 --- a/yazi-plugin/src/fs/fs.rs +++ b/yazi-plugin/src/fs/fs.rs @@ -4,7 +4,7 @@ use tokio::fs; use crate::{bindings::{Cast, Cha}, url::UrlRef}; pub fn install(lua: &Lua) -> mlua::Result<()> { - lua.globals().set( + lua.globals().raw_set( "fs", lua.create_table_from([ ( diff --git a/yazi-plugin/src/isolate/entry.rs b/yazi-plugin/src/isolate/entry.rs index 7ac0a7f9..66986823 100644 --- a/yazi-plugin/src/isolate/entry.rs +++ b/yazi-plugin/src/isolate/entry.rs @@ -8,12 +8,7 @@ pub async fn entry(name: String, args: Vec) -> mlua::Result<()> { LOADED.ensure(&name).await.into_lua_err()?; tokio::task::spawn_blocking(move || { - let lua = slim_lua()?; - let globals = lua.globals(); - - globals.raw_set("YAZI_PLUGIN_NAME", lua.create_string(&name)?)?; - globals.raw_set("YAZI_SYNC_CALLS", 0)?; - + let lua = slim_lua(&name)?; let plugin: Table = if let Some(b) = LOADED.read().get(&name) { lua.load(b).call(())? } else { diff --git a/yazi-plugin/src/isolate/isolate.rs b/yazi-plugin/src/isolate/isolate.rs index 0bc6779e..e0e0de17 100644 --- a/yazi-plugin/src/isolate/isolate.rs +++ b/yazi-plugin/src/isolate/isolate.rs @@ -2,7 +2,7 @@ use mlua::Lua; use crate::{bindings, elements}; -pub fn slim_lua() -> mlua::Result { +pub fn slim_lua(name: &str) -> mlua::Result { let lua = Lua::new(); // Base @@ -23,7 +23,13 @@ pub fn slim_lua() -> mlua::Result { elements::Rect::register(&lua)?; elements::Rect::install(&lua, &ui)?; elements::Span::install(&lua, &ui)?; - lua.globals().set("ui", ui)?; + + { + let globals = lua.globals(); + globals.raw_set("ui", ui)?; + globals.raw_set("YAZI_PLUGIN_NAME", lua.create_string(name)?)?; + globals.raw_set("YAZI_SYNC_CALLS", 0)?; + } Ok(lua) } diff --git a/yazi-plugin/src/isolate/peek.rs b/yazi-plugin/src/isolate/peek.rs index 4fa1b516..8e6cff60 100644 --- a/yazi-plugin/src/isolate/peek.rs +++ b/yazi-plugin/src/isolate/peek.rs @@ -17,7 +17,7 @@ pub fn peek(cmd: &Cmd, file: yazi_shared::fs::File, skip: usize) -> Cancellation let future = async { LOADED.ensure(&name).await.into_lua_err()?; - let lua = slim_lua()?; + let lua = slim_lua(&name)?; lua.set_hook( HookTriggers::new().on_calls().on_returns().every_nth_instruction(2000), move |_, _| { @@ -30,10 +30,10 @@ pub fn peek(cmd: &Cmd, file: yazi_shared::fs::File, skip: usize) -> Cancellation } else { return Err("unloaded plugin".into_lua_err()); }; - plugin.set("file", File::cast(&lua, file)?)?; - plugin.set("skip", skip)?; - plugin.set("area", Rect::cast(&lua, LAYOUT.load().preview)?)?; - plugin.set("window", Window::default())?; + plugin.raw_set("file", File::cast(&lua, file)?)?; + plugin.raw_set("skip", skip)?; + plugin.raw_set("area", Rect::cast(&lua, LAYOUT.load().preview)?)?; + plugin.raw_set("window", Window::default())?; if ct2.is_cancelled() { Ok(()) } else { plugin.call_async_method("peek", ()).await } }; @@ -58,10 +58,10 @@ pub fn peek(cmd: &Cmd, file: yazi_shared::fs::File, skip: usize) -> Cancellation pub fn peek_sync(cmd: &Cmd, file: yazi_shared::fs::File, skip: usize) { let data = OptData { cb: Some(Box::new(move |_, plugin| { - plugin.set("file", File::cast(&LUA, file)?)?; - plugin.set("skip", skip)?; - plugin.set("area", Rect::cast(&LUA, LAYOUT.load().preview)?)?; - plugin.set("window", Window::default())?; + plugin.raw_set("file", File::cast(&LUA, file)?)?; + plugin.raw_set("skip", skip)?; + plugin.raw_set("area", Rect::cast(&LUA, LAYOUT.load().preview)?)?; + plugin.raw_set("window", Window::default())?; plugin.call_method("peek", ()) })), ..Default::default() diff --git a/yazi-plugin/src/isolate/preload.rs b/yazi-plugin/src/isolate/preload.rs index 8e25fd9b..7b40709b 100644 --- a/yazi-plugin/src/isolate/preload.rs +++ b/yazi-plugin/src/isolate/preload.rs @@ -14,7 +14,7 @@ pub async fn preload( let name = name.to_owned(); tokio::task::spawn_blocking(move || { - let lua = slim_lua()?; + let lua = slim_lua(&name)?; let plugin: Table = if let Some(b) = LOADED.read().get(&name) { lua.load(b).call(())? } else { @@ -26,12 +26,12 @@ pub async fn preload( return Err("no files".into_lua_err()); } - plugin.set("skip", 0)?; - plugin.set("area", Rect::cast(&lua, LAYOUT.load().preview)?)?; + plugin.raw_set("skip", 0)?; + plugin.raw_set("area", Rect::cast(&lua, LAYOUT.load().preview)?)?; if multi { - plugin.set("files", files)?; + plugin.raw_set("files", files)?; } else { - plugin.set("file", files.remove(0))?; + plugin.raw_set("file", files.remove(0))?; } Handle::current().block_on(plugin.call_async_method("preload", ())) diff --git a/yazi-plugin/src/isolate/seek.rs b/yazi-plugin/src/isolate/seek.rs index 65b2ef6d..56a3cdcc 100644 --- a/yazi-plugin/src/isolate/seek.rs +++ b/yazi-plugin/src/isolate/seek.rs @@ -7,8 +7,8 @@ use crate::{bindings::{Cast, File}, elements::Rect, OptData, LUA}; pub fn seek_sync(cmd: &Cmd, file: yazi_shared::fs::File, units: i16) { let data = OptData { cb: Some(Box::new(move |_, plugin| { - plugin.set("file", File::cast(&LUA, file)?)?; - plugin.set("area", Rect::cast(&LUA, LAYOUT.load().preview)?)?; + plugin.raw_set("file", File::cast(&LUA, file)?)?; + plugin.raw_set("area", Rect::cast(&LUA, LAYOUT.load().preview)?)?; plugin.call_method("seek", units) })), ..Default::default() diff --git a/yazi-plugin/src/process/child.rs b/yazi-plugin/src/process/child.rs index 8a1668c1..18c9d0e7 100644 --- a/yazi-plugin/src/process/child.rs +++ b/yazi-plugin/src/process/child.rs @@ -61,7 +61,7 @@ impl UserData for Child { }); methods.add_async_method_mut("read_line", |_, me, ()| async move { Ok(read_line(me).await) }); methods.add_async_method_mut("read_line_with", |_, me, options: Table| async move { - let timeout: u64 = options.get("timeout")?; + let timeout: u64 = options.raw_get("timeout")?; match tokio::time::timeout(Duration::from_millis(timeout), read_line(me)).await { Ok(value) => Ok(value), Err(_) => Ok((String::new(), 3u8)), diff --git a/yazi-plugin/src/process/command.rs b/yazi-plugin/src/process/command.rs index 6184a67e..33a65ce4 100644 --- a/yazi-plugin/src/process/command.rs +++ b/yazi-plugin/src/process/command.rs @@ -30,7 +30,7 @@ impl Command { command.set_metatable(Some(lua.create_table_from([("__call", new)])?)); - lua.globals().set("Command", command) + lua.globals().raw_set("Command", command) } } diff --git a/yazi-plugin/src/url/url.rs b/yazi-plugin/src/url/url.rs index 26b641e0..30c5b7c6 100644 --- a/yazi-plugin/src/url/url.rs +++ b/yazi-plugin/src/url/url.rs @@ -42,7 +42,7 @@ impl Url { } pub fn install(lua: &Lua) -> mlua::Result<()> { - lua.globals().set( + lua.globals().raw_set( "Url", lua.create_function(|lua, url: mlua::String| { Self::cast(lua, yazi_shared::fs::Url::from(url.to_str()?)) diff --git a/yazi-plugin/src/utils/cache.rs b/yazi-plugin/src/utils/cache.rs index ba73a680..b0f9a31a 100644 --- a/yazi-plugin/src/utils/cache.rs +++ b/yazi-plugin/src/utils/cache.rs @@ -7,17 +7,17 @@ use crate::{bindings::{Cast, FileRef}, url::Url}; impl Utils { pub(super) fn cache(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set( + ya.raw_set( "file_cache", lua.create_function(|lua, t: Table| { - let file: FileRef = t.get("file")?; + let file: FileRef = t.raw_get("file")?; if file.url.parent() == Some(&PREVIEW.cache_dir) { return Ok(None); } let hex = { let mut digest = Md5::new_with_prefix(file.url.as_os_str().as_encoded_bytes()); - digest.update(&format!("//{:?}//{}", file.cha.modified, t.get("skip").unwrap_or(0))); + digest.update(&format!("//{:?}//{}", file.cha.modified, t.raw_get("skip").unwrap_or(0))); format!("{:x}", digest.finalize()) }; diff --git a/yazi-plugin/src/utils/call.rs b/yazi-plugin/src/utils/call.rs index 02e0a1f8..aa966478 100644 --- a/yazi-plugin/src/utils/call.rs +++ b/yazi-plugin/src/utils/call.rs @@ -50,7 +50,7 @@ impl Utils { } pub(super) fn call(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set( + ya.raw_set( "render", lua.create_function(|_, ()| { render!(); @@ -58,7 +58,7 @@ impl Utils { })?, )?; - ya.set( + ya.raw_set( "app_emit", lua.create_function(|_, (name, table, data): (String, Table, Option)| { emit!(Call(Self::create_cmd(name, table, data)?, Layer::App)); @@ -66,7 +66,7 @@ impl Utils { })?, )?; - ya.set( + ya.raw_set( "manager_emit", lua.create_function(|_, (name, table, data): (String, Table, Option)| { emit!(Call(Self::create_cmd(name, table, data)?, Layer::Manager)); diff --git a/yazi-plugin/src/utils/image.rs b/yazi-plugin/src/utils/image.rs index 7cc8e1c5..9a13e684 100644 --- a/yazi-plugin/src/utils/image.rs +++ b/yazi-plugin/src/utils/image.rs @@ -6,7 +6,7 @@ use crate::{elements::RectRef, url::UrlRef}; impl Utils { pub(super) fn image(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set( + ya.raw_set( "image_show", lua.create_async_function(|lua, (url, rect): (UrlRef, RectRef)| async move { if let Ok(size) = ADAPTOR.image_show(&url, *rect).await { @@ -17,7 +17,7 @@ impl Utils { })?, )?; - ya.set( + ya.raw_set( "image_precache", lua.create_async_function(|_, (src, dist): (UrlRef, UrlRef)| async move { Ok(Image::precache(&src, dist.to_path_buf()).await.is_ok()) diff --git a/yazi-plugin/src/utils/layer.rs b/yazi-plugin/src/utils/layer.rs index d953d48f..ca5337ab 100644 --- a/yazi-plugin/src/utils/layer.rs +++ b/yazi-plugin/src/utils/layer.rs @@ -25,7 +25,7 @@ impl Utils { } pub(super) fn layer(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set( + ya.raw_set( "which", lua.create_async_function(|_, t: Table| async move { let (tx, mut rx) = mpsc::channel::(1); @@ -34,9 +34,9 @@ impl Utils { for (i, cand) in t.get::<_, Table>("cands")?.sequence_values::().enumerate() { let cand = cand?; cands.push(Control { - on: Self::parse_keys(cand.get("on")?)?, + on: Self::parse_keys(cand.raw_get("on")?)?, exec: vec![Cmd::args("callback", vec![i.to_string()]).with_data(tx.clone())], - desc: cand.get("desc").ok(), + desc: cand.raw_get("desc").ok(), }); } @@ -44,7 +44,7 @@ impl Utils { emit!(Call( Cmd::new("show") .with("layer", Layer::Which) - .with_bool("silent", t.get("silent").unwrap_or_default()) + .with_bool("silent", t.raw_get("silent").unwrap_or_default()) .with_data(cands), Layer::Which )); diff --git a/yazi-plugin/src/utils/log.rs b/yazi-plugin/src/utils/log.rs index e481307f..23b86774 100644 --- a/yazi-plugin/src/utils/log.rs +++ b/yazi-plugin/src/utils/log.rs @@ -5,9 +5,9 @@ use super::Utils; impl Utils { pub(super) fn log(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set("dbg", lua.create_function(|_, s: String| Ok(debug!("{s}")))?)?; + ya.raw_set("dbg", lua.create_function(|_, s: String| Ok(debug!("{s}")))?)?; - ya.set("err", lua.create_function(|_, s: String| Ok(error!("{s}")))?)?; + ya.raw_set("err", lua.create_function(|_, s: String| Ok(error!("{s}")))?)?; Ok(()) } diff --git a/yazi-plugin/src/utils/plugin.rs b/yazi-plugin/src/utils/plugin.rs index 13e90694..e65ef7e2 100644 --- a/yazi-plugin/src/utils/plugin.rs +++ b/yazi-plugin/src/utils/plugin.rs @@ -7,7 +7,7 @@ use crate::{OptData, ValueSendable}; impl Utils { pub(super) fn plugin(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set( + ya.raw_set( "plugin_retrieve", lua.create_async_function( |_, (name, calls, args): (String, usize, Variadic)| async move { diff --git a/yazi-plugin/src/utils/preview.rs b/yazi-plugin/src/utils/preview.rs index f5bce8b9..54eec697 100644 --- a/yazi-plugin/src/utils/preview.rs +++ b/yazi-plugin/src/utils/preview.rs @@ -17,12 +17,12 @@ impl<'a> TryFrom> for PreviewLock { type Error = mlua::Error; fn try_from(t: Table) -> Result { - let file: FileRef = t.get("file")?; + let file: FileRef = t.raw_get("file")?; Ok(Self { url: file.url(), cha: file.cha, - skip: t.get("skip")?, - window: t.get("window")?, + skip: t.raw_get("skip")?, + window: t.raw_get("window")?, data: Default::default(), }) } @@ -30,10 +30,10 @@ impl<'a> TryFrom> for PreviewLock { impl Utils { pub(super) fn preview(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set( + ya.raw_set( "preview_code", lua.create_async_function(|lua, t: Table| async move { - let area: RectRef = t.get("area")?; + let area: RectRef = t.raw_get("area")?; let mut lock = PreviewLock::try_from(t)?; let text = @@ -49,10 +49,10 @@ impl Utils { })?, )?; - ya.set( + ya.raw_set( "preview_archive", lua.create_async_function(|lua, t: Table| async move { - let area: RectRef = t.get("area")?; + let area: RectRef = t.raw_get("area")?; let mut lock = PreviewLock::try_from(t)?; let lines: Vec<_> = match external::lsar(&lock.url, lock.skip, area.height as usize).await { @@ -72,7 +72,7 @@ impl Utils { })?, )?; - ya.set( + ya.raw_set( "preview_widgets", lua.create_async_function(|_, (t, widgets): (Table, Vec)| async move { let mut lock = PreviewLock::try_from(t)?; diff --git a/yazi-plugin/src/utils/target.rs b/yazi-plugin/src/utils/target.rs index 8f2b5336..ab9ec164 100644 --- a/yazi-plugin/src/utils/target.rs +++ b/yazi-plugin/src/utils/target.rs @@ -4,7 +4,7 @@ use super::Utils; impl Utils { pub(super) fn target(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set( + ya.raw_set( "target_family", lua.create_function(|_, ()| { #[cfg(unix)] diff --git a/yazi-plugin/src/utils/text.rs b/yazi-plugin/src/utils/text.rs index 55b49738..401084a7 100644 --- a/yazi-plugin/src/utils/text.rs +++ b/yazi-plugin/src/utils/text.rs @@ -7,7 +7,7 @@ use super::Utils; impl Utils { pub(super) fn text(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set( + ya.raw_set( "quote", lua.create_function(|_, s: mlua::String| { #[cfg(unix)] @@ -18,7 +18,7 @@ impl Utils { })?, )?; - ya.set( + ya.raw_set( "truncate", lua.create_function(|_, (text, max): (mlua::String, usize)| { let mut width = 0; diff --git a/yazi-plugin/src/utils/time.rs b/yazi-plugin/src/utils/time.rs index fadbb18e..4340ed34 100644 --- a/yazi-plugin/src/utils/time.rs +++ b/yazi-plugin/src/utils/time.rs @@ -6,14 +6,14 @@ use super::Utils; impl Utils { pub(super) fn time(lua: &Lua, ya: &Table) -> mlua::Result<()> { - ya.set( + ya.raw_set( "time", lua.create_function(|_, ()| { Ok(SystemTime::now().duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok()) })?, )?; - ya.set( + ya.raw_set( "sleep", lua.create_async_function(|_, secs: f64| async move { if secs < 0.0 { diff --git a/yazi-plugin/src/utils/user.rs b/yazi-plugin/src/utils/user.rs index ca5f271c..473fb3ac 100644 --- a/yazi-plugin/src/utils/user.rs +++ b/yazi-plugin/src/utils/user.rs @@ -10,11 +10,11 @@ impl Utils { use crate::utils::{HOSTNAME_CACHE, USERS_CACHE}; - ya.set("uid", lua.create_function(|_, ()| Ok(USERS_CACHE.get_current_uid()))?)?; + ya.raw_set("uid", lua.create_function(|_, ()| Ok(USERS_CACHE.get_current_uid()))?)?; - ya.set("gid", lua.create_function(|_, ()| Ok(USERS_CACHE.get_current_gid()))?)?; + ya.raw_set("gid", lua.create_function(|_, ()| Ok(USERS_CACHE.get_current_gid()))?)?; - ya.set( + ya.raw_set( "user_name", lua.create_function(|lua, uid: Option| { USERS_CACHE @@ -24,7 +24,7 @@ impl Utils { })?, )?; - ya.set( + ya.raw_set( "group_name", lua.create_function(|lua, gid: Option| { USERS_CACHE @@ -34,7 +34,7 @@ impl Utils { })?, )?; - ya.set( + ya.raw_set( "host_name", lua.create_function(|lua, ()| { HOSTNAME_CACHE diff --git a/yazi-plugin/src/utils/utils.rs b/yazi-plugin/src/utils/utils.rs index 571b25a8..a9be944a 100644 --- a/yazi-plugin/src/utils/utils.rs +++ b/yazi-plugin/src/utils/utils.rs @@ -20,7 +20,7 @@ pub fn install(lua: &mlua::Lua) -> mlua::Result<()> { Utils::time(lua, &ya)?; Utils::user(lua, &ya)?; - lua.globals().set("ya", ya) + lua.globals().raw_set("ya", ya) } pub fn init() {