mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-22 23:31:05 +00:00
perf: prefer raw_get() and raw_set()
This commit is contained in:
parent
4e7e135cb5
commit
d8abb3ed79
41 changed files with 97 additions and 96 deletions
|
|
@ -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>(())
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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>(())
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ impl Progress {
|
|||
) -> Vec<Vec<(u16, u16, ratatui::buffer::Cell)>> {
|
||||
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<AnyUserData>>("partial_render", ())? {
|
||||
let Some(w) = cast_to_renderable(widget) else {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -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>(())
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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())?),
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
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> {
|
||||
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> {
|
||||
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> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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() }))?,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<ListItem>)| {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -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<()> {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<()> {
|
||||
|
|
|
|||
|
|
@ -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())))
|
||||
|
|
|
|||
|
|
@ -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<Table<'a>> 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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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([
|
||||
(
|
||||
|
|
|
|||
|
|
@ -8,12 +8,7 @@ pub async fn entry(name: String, args: Vec<ValueSendable>) -> 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 {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use mlua::Lua;
|
|||
|
||||
use crate::{bindings, elements};
|
||||
|
||||
pub fn slim_lua() -> mlua::Result<Lua> {
|
||||
pub fn slim_lua(name: &str) -> mlua::Result<Lua> {
|
||||
let lua = Lua::new();
|
||||
|
||||
// Base
|
||||
|
|
@ -23,7 +23,13 @@ pub fn slim_lua() -> mlua::Result<Lua> {
|
|||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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", ()))
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()?))
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Value>)| {
|
||||
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<Value>)| {
|
||||
emit!(Call(Self::create_cmd(name, table, data)?, Layer::Manager));
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
|
|
@ -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::<usize>(1);
|
||||
|
|
@ -34,9 +34,9 @@ impl Utils {
|
|||
for (i, cand) in t.get::<_, Table>("cands")?.sequence_values::<Table>().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
|
||||
));
|
||||
|
|
|
|||
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Value>)| async move {
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ impl<'a> TryFrom<Table<'a>> for PreviewLock {
|
|||
type Error = mlua::Error;
|
||||
|
||||
fn try_from(t: Table) -> Result<Self, Self::Error> {
|
||||
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<Table<'a>> 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<AnyUserData>)| async move {
|
||||
let mut lock = PreviewLock::try_from(t)?;
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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<u32>| {
|
||||
USERS_CACHE
|
||||
|
|
@ -24,7 +24,7 @@ impl Utils {
|
|||
})?,
|
||||
)?;
|
||||
|
||||
ya.set(
|
||||
ya.raw_set(
|
||||
"group_name",
|
||||
lua.create_function(|lua, gid: Option<u32>| {
|
||||
USERS_CACHE
|
||||
|
|
@ -34,7 +34,7 @@ impl Utils {
|
|||
})?,
|
||||
)?;
|
||||
|
||||
ya.set(
|
||||
ya.raw_set(
|
||||
"host_name",
|
||||
lua.create_function(|lua, ()| {
|
||||
HOSTNAME_CACHE
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue