Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Oct 28, 2024
1 parent 176773b commit a896b44
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 16 deletions.
4 changes: 3 additions & 1 deletion yazi-plugin/src/bindings/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use mlua::Lua;

pub trait Cast<T> {
fn cast(lua: &mlua::Lua, data: T) -> mlua::Result<mlua::AnyUserData>;
fn cast(lua: &Lua, data: T) -> mlua::Result<mlua::AnyUserData>;
}
2 changes: 1 addition & 1 deletion yazi-plugin/src/bindings/permit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{mem, ops::Deref};
use mlua::{UserData, prelude::LuaUserDataMethods};
use tokio::sync::SemaphorePermit;

pub type PermitRef<'lua, F> = mlua::UserDataRef<Permit<F>>;
pub type PermitRef<F> = mlua::UserDataRef<Permit<F>>;

pub struct Permit<F: FnOnce()> {
inner: Option<SemaphorePermit<'static>>,
Expand Down
4 changes: 2 additions & 2 deletions yazi-plugin/src/bindings/position.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{ops::Deref, str::FromStr};

use mlua::{ExternalResult, IntoLua};
use mlua::{ExternalResult, IntoLua, Lua};

pub struct Position(yazi_config::popup::Position);

Expand Down Expand Up @@ -33,7 +33,7 @@ impl TryFrom<mlua::Table> for Position {
}

impl IntoLua for Position {
fn into_lua(self, lua: &mlua::Lua) -> mlua::Result<mlua::Value> {
fn into_lua(self, lua: &Lua) -> mlua::Result<mlua::Value> {
lua
.create_table_from([
(1.into_lua(lua)?, self.origin.to_string().into_lua(lua)?),
Expand Down
4 changes: 2 additions & 2 deletions yazi-plugin/src/bindings/range.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use mlua::IntoLua;
use mlua::{IntoLua, Lua};

pub struct Range<T>(std::ops::Range<T>);

Expand All @@ -10,7 +10,7 @@ impl<T> IntoLua for Range<T>
where
T: IntoLua,
{
fn into_lua(self, lua: &mlua::Lua) -> mlua::Result<mlua::Value> {
fn into_lua(self, lua: &Lua) -> mlua::Result<mlua::Value> {
lua.create_sequence_from([self.0.start, self.0.end])?.into_lua(lua)
}
}
4 changes: 3 additions & 1 deletion yazi-plugin/src/cha/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![allow(clippy::module_inception)]

use mlua::Lua;

yazi_macro::mod_flat!(cha);

pub fn pour(lua: &mlua::Lua) -> mlua::Result<()> {
pub fn pour(lua: &Lua) -> mlua::Result<()> {
cha::Cha::register(lua)?;
cha::Cha::install(lua)?;

Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/src/file/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use mlua::{AnyUserData, Lua, Table, UserDataRef};

use crate::{bindings::Cast, impl_file_fields, impl_file_methods};

pub type FileRef<'lua> = UserDataRef<yazi_shared::fs::File>;
pub type FileRef = UserDataRef<yazi_shared::fs::File>;

pub struct File;

Expand Down
4 changes: 3 additions & 1 deletion yazi-plugin/src/file/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![allow(clippy::module_inception)]

use mlua::Lua;

yazi_macro::mod_flat!(file);

pub fn pour(lua: &mlua::Lua) -> mlua::Result<()> {
pub fn pour(lua: &Lua) -> mlua::Result<()> {
file::File::register(lua)?;
file::File::install(lua)?;

Expand Down
6 changes: 4 additions & 2 deletions yazi-plugin/src/loader/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![allow(clippy::module_inception)]

use mlua::Lua;

yazi_macro::mod_flat!(loader require);

pub(super) fn init() { LOADER.with(<_>::default); }

pub(super) fn install(lua: &mlua::Lua) -> mlua::Result<()> { Require::install(lua) }
pub(super) fn install(lua: &Lua) -> mlua::Result<()> { Require::install(lua) }

pub(super) fn install_isolate(lua: &mlua::Lua) -> mlua::Result<()> { Require::install_isolate(lua) }
pub(super) fn install_isolate(lua: &Lua) -> mlua::Result<()> { Require::install_isolate(lua) }
4 changes: 3 additions & 1 deletion yazi-plugin/src/pubsub/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![allow(clippy::module_inception)]

use mlua::Lua;

yazi_macro::mod_flat!(pubsub);

pub(super) fn install(lua: &'static mlua::Lua) -> mlua::Result<()> {
pub(super) fn install(lua: &'static Lua) -> mlua::Result<()> {
Pubsub::install(lua)?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct RuntimeFrame {
calls: usize,
}

pub type RtRef<'lua> = mlua::UserDataRefMut<Runtime>;
pub type RtRef = mlua::UserDataRefMut<Runtime>;

impl Runtime {
pub fn new(id: &str) -> Self {
Expand Down
4 changes: 3 additions & 1 deletion yazi-plugin/src/url/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#![allow(clippy::module_inception)]

use mlua::Lua;

yazi_macro::mod_flat!(url);

pub fn pour(lua: &mlua::Lua) -> mlua::Result<()> {
pub fn pour(lua: &Lua) -> mlua::Result<()> {
url::Url::register(lua)?;
url::Url::install(lua)?;

Expand Down
6 changes: 4 additions & 2 deletions yazi-plugin/src/utils/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use mlua::Lua;

#[cfg(unix)]
pub(super) static HOSTNAME_CACHE: std::sync::OnceLock<Option<String>> = std::sync::OnceLock::new();

pub(super) struct Utils;

pub fn install(lua: &'static mlua::Lua) -> mlua::Result<()> {
pub fn install(lua: &'static Lua) -> mlua::Result<()> {
let ya = lua.create_table()?;

Utils::app(lua, &ya)?;
Expand All @@ -22,7 +24,7 @@ pub fn install(lua: &'static mlua::Lua) -> mlua::Result<()> {
lua.globals().raw_set("ya", ya)
}

pub fn install_isolate(lua: &mlua::Lua) -> mlua::Result<()> {
pub fn install_isolate(lua: &Lua) -> mlua::Result<()> {
let ya = lua.create_table()?;

Utils::app(lua, &ya)?;
Expand Down

0 comments on commit a896b44

Please sign in to comment.