diff --git a/yazi-fm/src/lives/selected.rs b/yazi-fm/src/lives/selected.rs index de75f2148..0b7c99393 100644 --- a/yazi-fm/src/lives/selected.rs +++ b/yazi-fm/src/lives/selected.rs @@ -32,7 +32,7 @@ impl UserData for Selected { methods.add_meta_method(MetaMethod::Pairs, |lua, me, ()| { let iter = lua.create_function( - // TODO: UserDataRef + // FIXME: UserDataRef |lua, mut iter: UserDataRefMut, _>>| { if let Some(next) = iter.next() { (next.0, Url::cast(lua, next.1.clone())?).into_lua_multi(lua) diff --git a/yazi-fm/src/lives/yanked.rs b/yazi-fm/src/lives/yanked.rs index 0f1ec782e..6a002d822 100644 --- a/yazi-fm/src/lives/yanked.rs +++ b/yazi-fm/src/lives/yanked.rs @@ -35,7 +35,7 @@ impl UserData for Yanked { methods.add_meta_method(MetaMethod::Pairs, |lua, me, ()| { let iter = lua.create_function( - // TODO: UserDataRef + // FIXME: UserDataRef |lua, mut iter: UserDataRefMut, _>>| { if let Some(next) = iter.next() { (next.0, Url::cast(lua, next.1.clone())?).into_lua_multi(lua) diff --git a/yazi-plugin/src/bindings/permit.rs b/yazi-plugin/src/bindings/permit.rs index dd8c01d44..bb975f062 100644 --- a/yazi-plugin/src/bindings/permit.rs +++ b/yazi-plugin/src/bindings/permit.rs @@ -3,6 +3,8 @@ use std::{mem, ops::Deref}; use mlua::{UserData, prelude::LuaUserDataMethods}; use tokio::sync::SemaphorePermit; +pub type PermitRef<'lua, F> = mlua::UserDataRef>; + pub struct Permit { inner: Option>, destruct: Option, diff --git a/yazi-plugin/src/cha/cha.rs b/yazi-plugin/src/cha/cha.rs index ab9c8ed78..95e0ed136 100644 --- a/yazi-plugin/src/cha/cha.rs +++ b/yazi-plugin/src/cha/cha.rs @@ -3,7 +3,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; use mlua::{AnyUserData, ExternalError, Lua, Table, UserDataFields, UserDataMethods}; use yazi_shared::fs::ChaKind; -use crate::{Runtime, bindings::Cast}; +use crate::{RtRef, bindings::Cast}; pub struct Cha; @@ -76,33 +76,23 @@ impl Cha { // TODO: remove these deprecated properties in the future { reg.add_field_method_get("length", |lua, me| { - lua - .named_registry_value::("rt")? - .borrow_scoped(|rt: &Runtime| warn_deprecated(rt.current()))?; + warn_deprecated(lua.named_registry_value::("rt")?.current()); Ok(me.len) }); reg.add_field_method_get("created", |lua, me| { - lua - .named_registry_value::("rt")? - .borrow_scoped(|rt: &Runtime| warn_deprecated(rt.current()))?; + warn_deprecated(lua.named_registry_value::("rt")?.current()); Ok(me.btime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok())) }); reg.add_field_method_get("modified", |lua, me| { - lua - .named_registry_value::("rt")? - .borrow_scoped(|rt: &Runtime| warn_deprecated(rt.current()))?; + warn_deprecated(lua.named_registry_value::("rt")?.current()); Ok(me.mtime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok())) }); reg.add_field_method_get("accessed", |lua, me| { - lua - .named_registry_value::("rt")? - .borrow_scoped(|rt: &Runtime| warn_deprecated(rt.current()))?; + warn_deprecated(lua.named_registry_value::("rt")?.current()); Ok(me.atime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok())) }); reg.add_method("permissions", |lua, _me, ()| { - lua - .named_registry_value::("rt")? - .borrow_scoped(|rt: &Runtime| warn_deprecated(rt.current()))?; + warn_deprecated(lua.named_registry_value::("rt")?.current()); Ok( #[cfg(unix)] Some(yazi_shared::fs::permissions(_me.mode, _me.is_dummy())), diff --git a/yazi-plugin/src/elements/paragraph.rs b/yazi-plugin/src/elements/paragraph.rs index b66d86dea..7bb9c1b79 100644 --- a/yazi-plugin/src/elements/paragraph.rs +++ b/yazi-plugin/src/elements/paragraph.rs @@ -1,9 +1,9 @@ use std::time::Duration; -use mlua::{AnyUserData, FromLua, Lua, MultiValue, Table, Value}; +use mlua::{FromLua, Lua, MultiValue, Table, Value}; use super::Rect; -use crate::Runtime; +use crate::RtRef; static WARNED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); @@ -36,9 +36,7 @@ impl Paragraph { ( "__call", lua.create_function(|lua, (_, area, lines): (Table, Rect, Value)| { - lua - .named_registry_value::("rt")? - .borrow_scoped(|rt: &Runtime| warn_deprecated(rt.current()))?; + warn_deprecated(lua.named_registry_value::("rt")?.current()); lua .load(mlua::chunk! { return ui.Text($lines):area($area) @@ -49,9 +47,7 @@ impl Paragraph { ( "__index", lua.create_function(|lua, (_, key): (Table, mlua::String)| { - lua - .named_registry_value::("rt")? - .borrow_scoped(|rt: &Runtime| warn_deprecated(rt.current()))?; + warn_deprecated(lua.named_registry_value::("rt")?.current()); lua .load(mlua::chunk! { return ui.Text[$key] diff --git a/yazi-plugin/src/elements/text.rs b/yazi-plugin/src/elements/text.rs index 0aad70d18..66b0ec630 100644 --- a/yazi-plugin/src/elements/text.rs +++ b/yazi-plugin/src/elements/text.rs @@ -31,10 +31,7 @@ impl Text { let new = lua.create_function(|_, (_, value): (Table, Value)| Text::try_from(value))?; let parse = lua.create_function(|_, code: mlua::String| { - todo!(); - Ok(1) - // Ok(Text { inner: code.into_text().into_lua_err()?, ..Default::default() - // }) + Ok(Text { inner: code.as_bytes().into_text().into_lua_err()?, ..Default::default() }) })?; let text = lua.create_table_from([ diff --git a/yazi-plugin/src/file/file.rs b/yazi-plugin/src/file/file.rs index 2643a88e3..e20c587c1 100644 --- a/yazi-plugin/src/file/file.rs +++ b/yazi-plugin/src/file/file.rs @@ -2,6 +2,8 @@ use mlua::{AnyUserData, Lua, Table, UserDataRef}; use crate::{bindings::Cast, impl_file_fields, impl_file_methods}; +pub type FileRef<'lua> = UserDataRef; + pub struct File; impl File { diff --git a/yazi-plugin/src/fs/fs.rs b/yazi-plugin/src/fs/fs.rs index 609ab7cfd..9fa6af13c 100644 --- a/yazi-plugin/src/fs/fs.rs +++ b/yazi-plugin/src/fs/fs.rs @@ -3,7 +3,7 @@ use mlua::{ExternalError, ExternalResult, IntoLuaMulti, Lua, Table, Value}; use tokio::fs; use yazi_shared::fs::remove_dir_clean; -use crate::{bindings::Cast, cha::Cha, file::File, url::Url}; +use crate::{bindings::Cast, cha::Cha, file::File, url::{Url, UrlRef}}; pub fn install(lua: &Lua) -> mlua::Result<()> { lua.globals().raw_set( diff --git a/yazi-plugin/src/runtime.rs b/yazi-plugin/src/runtime.rs index 58c8505c2..2da617197 100644 --- a/yazi-plugin/src/runtime.rs +++ b/yazi-plugin/src/runtime.rs @@ -13,6 +13,8 @@ struct RuntimeFrame { calls: usize, } +pub type RtRef<'lua> = mlua::UserDataRefMut; + impl Runtime { pub fn new(id: &str) -> Self { Self { diff --git a/yazi-plugin/src/url/url.rs b/yazi-plugin/src/url/url.rs index 2c602b132..8cc9d9949 100644 --- a/yazi-plugin/src/url/url.rs +++ b/yazi-plugin/src/url/url.rs @@ -2,6 +2,8 @@ use mlua::{AnyUserData, ExternalError, Lua, MetaMethod, UserDataFields, UserData use crate::bindings::Cast; +pub type UrlRef = UserDataRef; + pub struct Url; impl Url { diff --git a/yazi-plugin/src/utils/text.rs b/yazi-plugin/src/utils/text.rs index d6932ddee..74f626ab8 100644 --- a/yazi-plugin/src/utils/text.rs +++ b/yazi-plugin/src/utils/text.rs @@ -26,15 +26,14 @@ impl Utils { ya.raw_set( "quote", - lua.create_function(|_, (s, unix): (mlua::String, Option)| { - todo!(); - Ok(1) - // let s = match unix { - // Some(true) => yazi_shared::shell::escape_unix(&s.to_str()?), - // Some(false) => yazi_shared::shell::escape_windows(&s.to_str()?), - // None => yazi_shared::shell::escape_native(&s.to_str()?), - // }; - // Ok(s.into_owned()) + lua.create_function(|lua, (s, unix): (mlua::String, Option)| { + let s = s.to_str()?; + let s = match unix { + Some(true) => yazi_shared::shell::escape_unix(s.as_ref()), + Some(false) => yazi_shared::shell::escape_windows(s.as_ref()), + None => yazi_shared::shell::escape_native(s.as_ref()), + }; + lua.create_string(s.as_ref()) })?, )?;