mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: rename cf to rt (#2393)
This commit is contained in:
parent
f11f77d7b9
commit
133c6ebc9d
19 changed files with 49 additions and 49 deletions
|
|
@ -27,11 +27,11 @@ impl App {
|
||||||
_ = Lives::scope(&self.cx, || {
|
_ = Lives::scope(&self.cx, || {
|
||||||
let body = payload.body.into_lua(&LUA)?;
|
let body = payload.body.into_lua(&LUA)?;
|
||||||
for (id, cb) in handlers {
|
for (id, cb) in handlers {
|
||||||
LUA.named_registry_value::<RtRefMut>("rt")?.push(&id);
|
LUA.named_registry_value::<RtRefMut>("ir")?.push(&id);
|
||||||
if let Err(e) = cb.call::<()>(body.clone()) {
|
if let Err(e) = cb.call::<()>(body.clone()) {
|
||||||
error!("Failed to run `{kind}` event handler in your `{id}` plugin: {e}");
|
error!("Failed to run `{kind}` event handler in your `{id}` plugin: {e}");
|
||||||
}
|
}
|
||||||
LUA.named_registry_value::<RtRefMut>("rt")?.pop();
|
LUA.named_registry_value::<RtRefMut>("ir")?.pop();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -55,11 +55,11 @@ impl App {
|
||||||
return self.cx.tasks.plugin_micro(opt);
|
return self.cx.tasks.plugin_micro(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
match LUA.named_registry_value::<RtRefMut>("rt") {
|
match LUA.named_registry_value::<RtRefMut>("ir") {
|
||||||
Ok(mut r) => r.push(&opt.id),
|
Ok(mut r) => r.push(&opt.id),
|
||||||
Err(e) => return warn!("{e}"),
|
Err(e) => return warn!("{e}"),
|
||||||
}
|
}
|
||||||
defer! { _ = LUA.named_registry_value::<RtRefMut>("rt").map(|mut r| r.pop()) }
|
defer! { _ = LUA.named_registry_value::<RtRefMut>("ir").map(|mut r| r.pop()) }
|
||||||
|
|
||||||
let plugin = match LOADER.load_with(&LUA, &opt.id, chunk) {
|
let plugin = match LOADER.load_with(&LUA, &opt.id, chunk) {
|
||||||
Ok(t) => t,
|
Ok(t) => t,
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ function Entity:found()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:symlink()
|
function Entity:symlink()
|
||||||
if not cf.manager.show_symlink then
|
if not rt.manager.show_symlink then
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ function Tab:new(area, tab)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Tab:layout()
|
function Tab:layout()
|
||||||
local ratio = cf.manager.ratio
|
local ratio = rt.manager.ratio
|
||||||
self._chunks = ui.Layout()
|
self._chunks = ui.Layout()
|
||||||
:direction(ui.Layout.HORIZONTAL)
|
:direction(ui.Layout.HORIZONTAL)
|
||||||
:constraints({
|
:constraints({
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ end
|
||||||
|
|
||||||
function M:spot_base(job)
|
function M:spot_base(job)
|
||||||
local url, cha = job.file.url, job.file.cha
|
local url, cha = job.file.url, job.file.cha
|
||||||
local spotter = cf.plugin.spotter(url, job.mime)
|
local spotter = rt.plugin.spotter(url, job.mime)
|
||||||
local previewer = cf.plugin.previewer(url, job.mime)
|
local previewer = rt.plugin.previewer(url, job.mime)
|
||||||
local fetchers = cf.plugin.fetchers(job.file, job.mime)
|
local fetchers = rt.plugin.fetchers(job.file, job.mime)
|
||||||
local preloaders = cf.plugin.preloaders(url, job.mime)
|
local preloaders = rt.plugin.preloaders(url, job.mime)
|
||||||
|
|
||||||
for i, v in ipairs(fetchers) do
|
for i, v in ipairs(fetchers) do
|
||||||
fetchers[i] = v.cmd
|
fetchers[i] = v.cmd
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ function M:peek(job)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ya.sleep(math.max(0, cf.preview.image_delay / 1000 + start - os.clock()))
|
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(cache, job.area)
|
ya.image_show(cache, job.area)
|
||||||
ya.preview_widgets(job, {})
|
ya.preview_widgets(job, {})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ function M:peek(job)
|
||||||
url = job.file.url
|
url = job.file.url
|
||||||
end
|
end
|
||||||
|
|
||||||
ya.sleep(math.max(0, cf.preview.image_delay / 1000 + start - os.clock()))
|
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(url, job.area)
|
ya.image_show(url, job.area)
|
||||||
ya.preview_widgets(job, {})
|
ya.preview_widgets(job, {})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ function M:peek(job)
|
||||||
if job.skip > 0 and i < job.skip + limit then
|
if job.skip > 0 and i < job.skip + limit then
|
||||||
ya.manager_emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true })
|
ya.manager_emit("peek", { math.max(0, i - limit), only_if = job.file.url, upper_bound = true })
|
||||||
else
|
else
|
||||||
lines = lines:gsub("\t", string.rep(" ", cf.preview.tab_size))
|
lines = lines:gsub("\t", string.rep(" ", rt.preview.tab_size))
|
||||||
ya.preview_widgets(job, {
|
ya.preview_widgets(job, {
|
||||||
ui.Text.parse(lines):area(job.area):wrap(cf.preview.wrap == "yes" and ui.Text.WRAP or ui.Text.WRAP_NO),
|
ui.Text.parse(lines):area(job.area):wrap(rt.preview.wrap == "yes" and ui.Text.WRAP or ui.Text.WRAP_NO),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ function M:peek(job)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ya.sleep(math.max(0, cf.preview.image_delay / 1000 + start - os.clock()))
|
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(cache, job.area)
|
ya.image_show(cache, job.area)
|
||||||
ya.preview_widgets(job, {})
|
ya.preview_widgets(job, {})
|
||||||
end
|
end
|
||||||
|
|
@ -31,9 +31,9 @@ function M:preload(job)
|
||||||
tostring(job.file.url),
|
tostring(job.file.url),
|
||||||
"-flatten",
|
"-flatten",
|
||||||
"-resize",
|
"-resize",
|
||||||
string.format("%dx%d^", cf.preview.max_width, cf.preview.max_height),
|
string.format("%dx%d^", rt.preview.max_width, rt.preview.max_height),
|
||||||
"-quality",
|
"-quality",
|
||||||
cf.preview.image_quality,
|
rt.preview.image_quality,
|
||||||
"-auto-orient",
|
"-auto-orient",
|
||||||
"JPG:" .. tostring(cache),
|
"JPG:" .. tostring(cache),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ function M:peek(job)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ya.sleep(math.max(0, cf.preview.image_delay / 1000 + start - os.clock()))
|
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(cache, job.area)
|
ya.image_show(cache, job.area)
|
||||||
ya.preview_widgets(job, {})
|
ya.preview_widgets(job, {})
|
||||||
end
|
end
|
||||||
|
|
@ -36,8 +36,8 @@ function M:preload(job)
|
||||||
"-f", job.skip + 1,
|
"-f", job.skip + 1,
|
||||||
"-l", job.skip + 1,
|
"-l", job.skip + 1,
|
||||||
"-singlefile",
|
"-singlefile",
|
||||||
"-jpeg", "-jpegopt", "quality=" .. cf.preview.image_quality,
|
"-jpeg", "-jpegopt", "quality=" .. rt.preview.image_quality,
|
||||||
"-scale-to-x", cf.preview.max_width, "-scale-to-y", "-1",
|
"-scale-to-x", rt.preview.max_width, "-scale-to-y", "-1",
|
||||||
tostring(job.file.url),
|
tostring(job.file.url),
|
||||||
tostring(cache),
|
tostring(cache),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ function M:peek(job)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
ya.sleep(math.max(0, cf.preview.image_delay / 1000 + start - os.clock()))
|
ya.sleep(math.max(0, rt.preview.image_delay / 1000 + start - os.clock()))
|
||||||
ya.image_show(cache, job.area)
|
ya.image_show(cache, job.area)
|
||||||
ya.preview_widgets(job, {})
|
ya.preview_widgets(job, {})
|
||||||
end
|
end
|
||||||
|
|
@ -51,7 +51,7 @@ function M:preload(job)
|
||||||
end
|
end
|
||||||
|
|
||||||
local ss = math.floor(meta.format.duration * percent / 100)
|
local ss = math.floor(meta.format.duration * percent / 100)
|
||||||
local qv = 31 - math.floor(cf.preview.image_quality * 0.3)
|
local qv = 31 - math.floor(rt.preview.image_quality * 0.3)
|
||||||
-- stylua: ignore
|
-- stylua: ignore
|
||||||
local status, err = Command("ffmpeg"):args({
|
local status, err = Command("ffmpeg"):args({
|
||||||
"-v", "quiet", "-threads", 1, "-hwaccel", "auto",
|
"-v", "quiet", "-threads", 1, "-hwaccel", "auto",
|
||||||
|
|
@ -60,7 +60,7 @@ function M:preload(job)
|
||||||
"-i", tostring(job.file.url),
|
"-i", tostring(job.file.url),
|
||||||
"-vframes", 1,
|
"-vframes", 1,
|
||||||
"-q:v", qv,
|
"-q:v", qv,
|
||||||
"-vf", string.format("scale=-1:'min(%d,ih)':flags=fast_bilinear", cf.preview.max_height),
|
"-vf", string.format("scale=-1:'min(%d,ih)':flags=fast_bilinear", rt.preview.max_height),
|
||||||
"-f", "image2",
|
"-f", "image2",
|
||||||
"-y", tostring(cache),
|
"-y", tostring(cache),
|
||||||
}):status()
|
}):status()
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
yazi_macro::mod_flat!(config plugin theme);
|
yazi_macro::mod_flat!(plugin runtime theme);
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ use crate::{Composer, url::Url};
|
||||||
pub const OPTS: SerializeOptions =
|
pub const OPTS: SerializeOptions =
|
||||||
SerializeOptions::new().serialize_none_to_null(false).serialize_unit_to_null(false);
|
SerializeOptions::new().serialize_none_to_null(false).serialize_unit_to_null(false);
|
||||||
|
|
||||||
pub struct Config<'a> {
|
pub struct Runtime<'a> {
|
||||||
lua: &'a Lua,
|
lua: &'a Lua,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Config<'a> {
|
impl<'a> Runtime<'a> {
|
||||||
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
|
||||||
Composer::make(lua, 5, |lua, key| {
|
Composer::make(lua, 5, |lua, key| {
|
||||||
match key {
|
match key {
|
||||||
|
|
@ -5,15 +5,15 @@ use crate::runtime::Runtime;
|
||||||
|
|
||||||
pub fn slim_lua(name: &str) -> mlua::Result<Lua> {
|
pub fn slim_lua(name: &str) -> mlua::Result<Lua> {
|
||||||
let lua = Lua::new();
|
let lua = Lua::new();
|
||||||
lua.set_named_registry_value("rt", Runtime::new(name))?;
|
lua.set_named_registry_value("ir", Runtime::new(name))?;
|
||||||
crate::config::Config::new(&lua).install_preview()?;
|
crate::config::Runtime::new(&lua).install_preview()?;
|
||||||
|
|
||||||
// Base
|
// Base
|
||||||
let globals = lua.globals();
|
let globals = lua.globals();
|
||||||
globals.raw_set("ui", crate::elements::compose(&lua)?)?;
|
globals.raw_set("ui", crate::elements::compose(&lua)?)?;
|
||||||
globals.raw_set("ya", crate::utils::compose(&lua, true)?)?;
|
globals.raw_set("ya", crate::utils::compose(&lua, true)?)?;
|
||||||
globals.raw_set("fs", crate::fs::compose(&lua)?)?;
|
globals.raw_set("fs", crate::fs::compose(&lua)?)?;
|
||||||
globals.raw_set("cf", crate::config::Config::compose(&lua)?)?;
|
globals.raw_set("rt", crate::config::Runtime::compose(&lua)?)?;
|
||||||
globals.raw_set("th", crate::config::Theme::compose(&lua)?)?;
|
globals.raw_set("th", crate::config::Theme::compose(&lua)?)?;
|
||||||
|
|
||||||
crate::bindings::Cha::install(&lua)?;
|
crate::bindings::Cha::install(&lua)?;
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ impl Require {
|
||||||
let s = &id.to_str()?;
|
let s = &id.to_str()?;
|
||||||
futures::executor::block_on(LOADER.ensure(s)).into_lua_err()?;
|
futures::executor::block_on(LOADER.ensure(s)).into_lua_err()?;
|
||||||
|
|
||||||
lua.named_registry_value::<RtRefMut>("rt")?.push(s);
|
lua.named_registry_value::<RtRefMut>("ir")?.push(s);
|
||||||
let mod_ = LOADER.load(lua, s);
|
let mod_ = LOADER.load(lua, s);
|
||||||
lua.named_registry_value::<RtRefMut>("rt")?.pop();
|
lua.named_registry_value::<RtRefMut>("ir")?.pop();
|
||||||
|
|
||||||
Self::create_mt(lua, s, mod_?, true)
|
Self::create_mt(lua, s, mod_?, true)
|
||||||
})?,
|
})?,
|
||||||
|
|
@ -31,9 +31,9 @@ impl Require {
|
||||||
let s = &id.to_str()?;
|
let s = &id.to_str()?;
|
||||||
LOADER.ensure(s).await.into_lua_err()?;
|
LOADER.ensure(s).await.into_lua_err()?;
|
||||||
|
|
||||||
lua.named_registry_value::<RtRefMut>("rt")?.push(s);
|
lua.named_registry_value::<RtRefMut>("ir")?.push(s);
|
||||||
let mod_ = LOADER.load(&lua, s);
|
let mod_ = LOADER.load(&lua, s);
|
||||||
lua.named_registry_value::<RtRefMut>("rt")?.pop();
|
lua.named_registry_value::<RtRefMut>("ir")?.pop();
|
||||||
|
|
||||||
Self::create_mt(&lua, s, mod_?, false)
|
Self::create_mt(&lua, s, mod_?, false)
|
||||||
})?,
|
})?,
|
||||||
|
|
@ -73,9 +73,9 @@ impl Require {
|
||||||
if sync {
|
if sync {
|
||||||
lua.create_function(move |lua, args: MultiValue| {
|
lua.create_function(move |lua, args: MultiValue| {
|
||||||
let (mod_, args) = Self::split_mod_and_args(lua, &id, args)?;
|
let (mod_, args) = Self::split_mod_and_args(lua, &id, args)?;
|
||||||
lua.named_registry_value::<RtRefMut>("rt")?.push(&id);
|
lua.named_registry_value::<RtRefMut>("ir")?.push(&id);
|
||||||
let result = mod_.call_function::<MultiValue>(&f, args);
|
let result = mod_.call_function::<MultiValue>(&f, args);
|
||||||
lua.named_registry_value::<RtRefMut>("rt")?.pop();
|
lua.named_registry_value::<RtRefMut>("ir")?.pop();
|
||||||
result
|
result
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -83,9 +83,9 @@ impl Require {
|
||||||
let (id, f) = (id.clone(), f.clone());
|
let (id, f) = (id.clone(), f.clone());
|
||||||
async move {
|
async move {
|
||||||
let (mod_, args) = Self::split_mod_and_args(&lua, &id, args)?;
|
let (mod_, args) = Self::split_mod_and_args(&lua, &id, args)?;
|
||||||
lua.named_registry_value::<RtRefMut>("rt")?.push(&id);
|
lua.named_registry_value::<RtRefMut>("ir")?.push(&id);
|
||||||
let result = mod_.call_async_function::<MultiValue>(&f, args).await;
|
let result = mod_.call_async_function::<MultiValue>(&f, args).await;
|
||||||
lua.named_registry_value::<RtRefMut>("rt")?.pop();
|
lua.named_registry_value::<RtRefMut>("ir")?.pop();
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ pub(super) fn init_lua() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stage_1(lua: &'static Lua) -> Result<()> {
|
fn stage_1(lua: &'static Lua) -> Result<()> {
|
||||||
lua.set_named_registry_value("rt", Runtime::default())?;
|
lua.set_named_registry_value("ir", Runtime::default())?;
|
||||||
crate::config::Config::new(lua).install_manager()?.install_theme()?;
|
crate::config::Runtime::new(lua).install_manager()?.install_theme()?;
|
||||||
|
|
||||||
// Base
|
// Base
|
||||||
let globals = lua.globals();
|
let globals = lua.globals();
|
||||||
|
|
@ -26,7 +26,7 @@ fn stage_1(lua: &'static Lua) -> Result<()> {
|
||||||
globals.raw_set("ya", crate::utils::compose(lua, false)?)?;
|
globals.raw_set("ya", crate::utils::compose(lua, false)?)?;
|
||||||
globals.raw_set("fs", crate::fs::compose(lua)?)?;
|
globals.raw_set("fs", crate::fs::compose(lua)?)?;
|
||||||
globals.raw_set("ps", crate::pubsub::compose(lua)?)?;
|
globals.raw_set("ps", crate::pubsub::compose(lua)?)?;
|
||||||
globals.raw_set("cf", crate::config::Config::compose(lua)?)?;
|
globals.raw_set("rt", crate::config::Runtime::compose(lua)?)?;
|
||||||
globals.raw_set("th", crate::config::Theme::compose(lua)?)?;
|
globals.raw_set("th", crate::config::Theme::compose(lua)?)?;
|
||||||
|
|
||||||
crate::Error::install(lua)?;
|
crate::Error::install(lua)?;
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ macro_rules! impl_file_methods {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! deprecate {
|
macro_rules! deprecate {
|
||||||
($lua:ident, $tt:tt) => {{
|
($lua:ident, $tt:tt) => {{
|
||||||
let id = match $lua.named_registry_value::<$crate::RtRef>("rt")?.current() {
|
let id = match $lua.named_registry_value::<$crate::RtRef>("ir")?.current() {
|
||||||
Some(id) => &format!("`{id}.yazi` plugin"),
|
Some(id) => &format!("`{id}.yazi` plugin"),
|
||||||
None => "`init.lua` config",
|
None => "`init.lua` config",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ impl Pubsub {
|
||||||
|
|
||||||
pub(super) fn sub(lua: &Lua) -> mlua::Result<Function> {
|
pub(super) fn sub(lua: &Lua) -> mlua::Result<Function> {
|
||||||
lua.create_function(|lua, (kind, f): (mlua::String, Function)| {
|
lua.create_function(|lua, (kind, f): (mlua::String, Function)| {
|
||||||
let rt = lua.named_registry_value::<RtRef>("rt")?;
|
let rt = lua.named_registry_value::<RtRef>("ir")?;
|
||||||
let Some(cur) = rt.current() else {
|
let Some(cur) = rt.current() else {
|
||||||
return Err("`sub()` must be called in a sync plugin").into_lua_err();
|
return Err("`sub()` must be called in a sync plugin").into_lua_err();
|
||||||
};
|
};
|
||||||
|
|
@ -35,7 +35,7 @@ impl Pubsub {
|
||||||
|
|
||||||
pub(super) fn sub_remote(lua: &Lua) -> mlua::Result<Function> {
|
pub(super) fn sub_remote(lua: &Lua) -> mlua::Result<Function> {
|
||||||
lua.create_function(|lua, (kind, f): (mlua::String, Function)| {
|
lua.create_function(|lua, (kind, f): (mlua::String, Function)| {
|
||||||
let rt = lua.named_registry_value::<RtRef>("rt")?;
|
let rt = lua.named_registry_value::<RtRef>("ir")?;
|
||||||
let Some(cur) = rt.current() else {
|
let Some(cur) = rt.current() else {
|
||||||
return Err("`sub_remote()` must be called in a sync plugin").into_lua_err();
|
return Err("`sub_remote()` must be called in a sync plugin").into_lua_err();
|
||||||
};
|
};
|
||||||
|
|
@ -48,7 +48,7 @@ impl Pubsub {
|
||||||
|
|
||||||
pub(super) fn unsub(lua: &Lua) -> mlua::Result<Function> {
|
pub(super) fn unsub(lua: &Lua) -> mlua::Result<Function> {
|
||||||
lua.create_function(|lua, kind: mlua::String| {
|
lua.create_function(|lua, kind: mlua::String| {
|
||||||
if let Some(cur) = lua.named_registry_value::<RtRef>("rt")?.current() {
|
if let Some(cur) = lua.named_registry_value::<RtRef>("ir")?.current() {
|
||||||
Ok(yazi_dds::Pubsub::unsub(cur, &kind.to_str()?))
|
Ok(yazi_dds::Pubsub::unsub(cur, &kind.to_str()?))
|
||||||
} else {
|
} else {
|
||||||
Err("`unsub()` must be called in a sync plugin").into_lua_err()
|
Err("`unsub()` must be called in a sync plugin").into_lua_err()
|
||||||
|
|
@ -58,7 +58,7 @@ impl Pubsub {
|
||||||
|
|
||||||
pub(super) fn unsub_remote(lua: &Lua) -> mlua::Result<Function> {
|
pub(super) fn unsub_remote(lua: &Lua) -> mlua::Result<Function> {
|
||||||
lua.create_function(|lua, kind: mlua::String| {
|
lua.create_function(|lua, kind: mlua::String| {
|
||||||
if let Some(cur) = lua.named_registry_value::<RtRef>("rt")?.current() {
|
if let Some(cur) = lua.named_registry_value::<RtRef>("ir")?.current() {
|
||||||
Ok(yazi_dds::Pubsub::unsub_remote(cur, &kind.to_str()?))
|
Ok(yazi_dds::Pubsub::unsub_remote(cur, &kind.to_str()?))
|
||||||
} else {
|
} else {
|
||||||
Err("`unsub_remote()` must be called in a sync plugin").into_lua_err()
|
Err("`unsub_remote()` must be called in a sync plugin").into_lua_err()
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ impl Utils {
|
||||||
pub(super) fn sync(lua: &Lua, isolate: bool) -> mlua::Result<Function> {
|
pub(super) fn sync(lua: &Lua, isolate: bool) -> mlua::Result<Function> {
|
||||||
if isolate {
|
if isolate {
|
||||||
lua.create_function(|lua, ()| {
|
lua.create_function(|lua, ()| {
|
||||||
let Some(block) = lua.named_registry_value::<RtRefMut>("rt")?.next_block() else {
|
let Some(block) = lua.named_registry_value::<RtRefMut>("ir")?.next_block() else {
|
||||||
return Err("`ya.sync()` must be called in a plugin").into_lua_err();
|
return Err("`ya.sync()` must be called in a plugin").into_lua_err();
|
||||||
};
|
};
|
||||||
|
|
||||||
lua.create_async_function(move |lua, args: MultiValue| async move {
|
lua.create_async_function(move |lua, args: MultiValue| async move {
|
||||||
let Some(cur) = lua.named_registry_value::<RtRef>("rt")?.current_owned() else {
|
let Some(cur) = lua.named_registry_value::<RtRef>("ir")?.current_owned() else {
|
||||||
return Err("block spawned by `ya.sync()` must be called in a plugin").into_lua_err();
|
return Err("block spawned by `ya.sync()` must be called in a plugin").into_lua_err();
|
||||||
};
|
};
|
||||||
Sendable::list_to_values(&lua, Self::retrieve(cur, block, args).await?)
|
Sendable::list_to_values(&lua, Self::retrieve(cur, block, args).await?)
|
||||||
|
|
@ -25,7 +25,7 @@ impl Utils {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
lua.create_function(|lua, f: Function| {
|
lua.create_function(|lua, f: Function| {
|
||||||
let mut rt = lua.named_registry_value::<RtRefMut>("rt")?;
|
let mut rt = lua.named_registry_value::<RtRefMut>("ir")?;
|
||||||
if !rt.put_block(f.clone()) {
|
if !rt.put_block(f.clone()) {
|
||||||
return Err("`ya.sync()` must be called in a plugin").into_lua_err();
|
return Err("`ya.sync()` must be called in a plugin").into_lua_err();
|
||||||
}
|
}
|
||||||
|
|
@ -84,7 +84,7 @@ impl Utils {
|
||||||
let callback: PluginCallback = {
|
let callback: PluginCallback = {
|
||||||
let id_ = id.clone();
|
let id_ = id.clone();
|
||||||
Box::new(move |lua, plugin| {
|
Box::new(move |lua, plugin| {
|
||||||
let Some(block) = lua.named_registry_value::<RtRef>("rt")?.get_block(&id_, calls) else {
|
let Some(block) = lua.named_registry_value::<RtRef>("ir")?.get_block(&id_, calls) else {
|
||||||
return Err("sync block not found".into_lua_err());
|
return Err("sync block not found".into_lua_err());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue