mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: upgrade to mlua v0.11.0 (#2989)
This commit is contained in:
parent
60a2382087
commit
548bb0d063
23 changed files with 50 additions and 36 deletions
31
Cargo.lock
generated
31
Cargo.lock
generated
|
|
@ -1247,6 +1247,15 @@ dependencies = [
|
||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.14.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.15"
|
version = "1.0.15"
|
||||||
|
|
@ -1394,18 +1403,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lua-src"
|
name = "lua-src"
|
||||||
version = "547.0.0"
|
version = "548.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1edaf29e3517b49b8b746701e5648ccb5785cde1c119062cbabbc5d5cd115e42"
|
checksum = "00bc4bd1f1d5c65b30717333cbec4fa7aa378978940a1bca62f404498d423233"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "luajit-src"
|
name = "luajit-src"
|
||||||
version = "210.5.12+a4f56a4"
|
version = "210.6.1+f9140a6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b3a8e7962a5368d5f264d045a5a255e90f9aa3fc1941ae15a8d2940d42cac671"
|
checksum = "813bd31f2759443affa687c0d9c5eb5cf6cb0e898810ab197408431d746054bf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"which",
|
"which",
|
||||||
|
|
@ -1474,9 +1483,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mlua"
|
name = "mlua"
|
||||||
version = "0.10.5"
|
version = "0.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c1f5f8fbebc7db5f671671134b9321c4b9aa9adeafccfd9a8c020ae45c6a35d0"
|
checksum = "de25fc513588ac1273aa8c6dc0fffee6d32c12f38dc75f5cdc74547121a107ef"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bstr",
|
"bstr",
|
||||||
|
|
@ -1495,9 +1504,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mlua-sys"
|
name = "mlua-sys"
|
||||||
version = "0.6.8"
|
version = "0.8.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "380c1f7e2099cafcf40e51d3a9f20a346977587aa4d012eae1f043149a728a93"
|
checksum = "bcdf7c9e260ca82aaa32ac11148941952b856bb8c69aa5a9e65962f21fcb8637"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
|
|
@ -1508,11 +1517,11 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mlua_derive"
|
name = "mlua_derive"
|
||||||
version = "0.10.1"
|
version = "0.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "870d71c172fcf491c6b5fb4c04160619a2ee3e5a42a1402269c66bcbf1dd4deb"
|
checksum = "465bddde514c4eb3b50b543250e97c1d4b284fa3ef7dc0ba2992c77545dbceb2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"itertools 0.13.0",
|
"itertools 0.14.0",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"proc-macro-error2",
|
"proc-macro-error2",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ globset = "0.4.16"
|
||||||
indexmap = { version = "2.10.0", features = [ "serde" ] }
|
indexmap = { version = "2.10.0", features = [ "serde" ] }
|
||||||
libc = "0.2.174"
|
libc = "0.2.174"
|
||||||
lru = "0.16.0"
|
lru = "0.16.0"
|
||||||
mlua = { version = "0.10.5", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serialize" ] }
|
mlua = { version = "0.11.1", features = [ "anyhow", "async", "error-send", "lua54", "macros", "serde" ] }
|
||||||
objc = "0.2.7"
|
objc = "0.2.7"
|
||||||
ordered-float = { version = "5.0.0", features = [ "serde" ] }
|
ordered-float = { version = "5.0.0", features = [ "serde" ] }
|
||||||
parking_lot = "0.12.4"
|
parking_lot = "0.12.4"
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ impl Bar {
|
||||||
lua.create_function(|_, (_, edge): (Table, Edge)| Ok(Self { edge, ..Default::default() }))?;
|
lua.create_function(|_, (_, edge): (Table, Edge)| Ok(Self { edge, ..Default::default() }))?;
|
||||||
|
|
||||||
let bar = lua.create_table()?;
|
let bar = lua.create_table()?;
|
||||||
bar.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
bar.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
bar.into_lua(lua)
|
bar.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ impl Border {
|
||||||
("QUADRANT_OUTSIDE", QUADRANT_OUTSIDE),
|
("QUADRANT_OUTSIDE", QUADRANT_OUTSIDE),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
border.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
border.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
border.into_lua(lua)
|
border.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ impl Clear {
|
||||||
let new = lua.create_function(|_, (_, area): (Table, Area)| Ok(Clear { area }))?;
|
let new = lua.create_function(|_, (_, area): (Table, Area)| Ok(Clear { area }))?;
|
||||||
|
|
||||||
let clear = lua.create_table()?;
|
let clear = lua.create_table()?;
|
||||||
clear.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
clear.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
clear.into_lua(lua)
|
clear.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ impl Gauge {
|
||||||
let new = lua.create_function(|_, _: Table| Ok(Gauge::default()))?;
|
let new = lua.create_function(|_, _: Table| Ok(Gauge::default()))?;
|
||||||
|
|
||||||
let gauge = lua.create_table()?;
|
let gauge = lua.create_table()?;
|
||||||
gauge.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
gauge.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
gauge.into_lua(lua)
|
gauge.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ impl Layout {
|
||||||
let new = lua.create_function(|_, _: Table| Ok(Self::default()))?;
|
let new = lua.create_function(|_, _: Table| Ok(Self::default()))?;
|
||||||
|
|
||||||
let layout = lua.create_table_from([("HORIZONTAL", HORIZONTAL), ("VERTICAL", VERTICAL)])?;
|
let layout = lua.create_table_from([("HORIZONTAL", HORIZONTAL), ("VERTICAL", VERTICAL)])?;
|
||||||
layout.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
layout.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
layout.into_lua(lua)
|
layout.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ impl Line {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let line = lua.create_table_from([("parse", parse)])?;
|
let line = lua.create_table_from([("parse", parse)])?;
|
||||||
line.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
line.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
line.into_lua(lua)
|
line.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ impl List {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let list = lua.create_table()?;
|
let list = lua.create_table()?;
|
||||||
list.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
list.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
list.into_lua(lua)
|
list.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ impl Pad {
|
||||||
),
|
),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
pad.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
pad.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
pad.into_lua(lua)
|
pad.into_lua(lua)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ impl Pos {
|
||||||
let new = lua.create_function(|_, (_, t): (Table, Table)| Self::try_from(t))?;
|
let new = lua.create_function(|_, (_, t): (Table, Table)| Self::try_from(t))?;
|
||||||
|
|
||||||
let position = lua.create_table()?;
|
let position = lua.create_table()?;
|
||||||
position.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
position.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
position.into_lua(lua)
|
position.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
@ -85,7 +85,7 @@ impl Pos {
|
||||||
impl UserData for Pos {
|
impl UserData for Pos {
|
||||||
fn add_fields<F: mlua::UserDataFields<Self>>(fields: &mut F) {
|
fn add_fields<F: mlua::UserDataFields<Self>>(fields: &mut F) {
|
||||||
// TODO: cache
|
// TODO: cache
|
||||||
fields.add_field_method_get(1, |_, me| Ok(me.origin.to_string()));
|
fields.add_field_method_get("1", |_, me| Ok(me.origin.to_string()));
|
||||||
fields.add_field_method_get("x", |_, me| Ok(me.offset.x));
|
fields.add_field_method_get("x", |_, me| Ok(me.offset.x));
|
||||||
fields.add_field_method_get("y", |_, me| Ok(me.offset.y));
|
fields.add_field_method_get("y", |_, me| Ok(me.offset.y));
|
||||||
fields.add_field_method_get("w", |_, me| Ok(me.offset.width));
|
fields.add_field_method_get("w", |_, me| Ok(me.offset.width));
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ impl Rect {
|
||||||
let rect = lua.create_table()?;
|
let rect = lua.create_table()?;
|
||||||
rect.set_metatable(Some(
|
rect.set_metatable(Some(
|
||||||
lua.create_table_from([(MetaMethod::Call.name(), new), (MetaMethod::Index.name(), index)])?,
|
lua.create_table_from([(MetaMethod::Call.name(), new), (MetaMethod::Index.name(), index)])?,
|
||||||
));
|
))?;
|
||||||
rect.into_lua(lua)
|
rect.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ impl Row {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let row = lua.create_table()?;
|
let row = lua.create_table()?;
|
||||||
row.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
row.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
row.into_lua(lua)
|
row.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ impl Span {
|
||||||
let new = lua.create_function(|_, (_, value): (Table, Value)| Span::try_from(value))?;
|
let new = lua.create_function(|_, (_, value): (Table, Value)| Span::try_from(value))?;
|
||||||
|
|
||||||
let span = lua.create_table()?;
|
let span = lua.create_table()?;
|
||||||
span.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
span.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
span.into_lua(lua)
|
span.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ impl Table {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let table = lua.create_table()?;
|
let table = lua.create_table()?;
|
||||||
table.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
table.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
table.into_lua(lua)
|
table.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ impl Text {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let text = lua.create_table_from([("parse", parse)])?;
|
let text = lua.create_table_from([("parse", parse)])?;
|
||||||
text.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
text.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
text.into_lua(lua)
|
text.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ impl Style {
|
||||||
let new = lua.create_function(|_, (_, value): (Table, Value)| Self::try_from(value))?;
|
let new = lua.create_function(|_, (_, value): (Table, Value)| Self::try_from(value))?;
|
||||||
|
|
||||||
let style = lua.create_table()?;
|
let style = lua.create_table()?;
|
||||||
style.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
style.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
style.into_lua(lua)
|
style.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ fn peek_async(
|
||||||
Ok(VmState::Continue)
|
Ok(VmState::Continue)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
)?;
|
||||||
|
|
||||||
let plugin = LOADER.load_once(&lua, &cmd.name)?;
|
let plugin = LOADER.load_once(&lua, &cmd.name)?;
|
||||||
let job = lua.create_table_from([
|
let job = lua.create_table_from([
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ pub async fn preload(
|
||||||
Ok(VmState::Continue)
|
Ok(VmState::Continue)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
)?;
|
||||||
|
|
||||||
let plugin = LOADER.load_once(&lua, &cmd.name)?;
|
let plugin = LOADER.load_once(&lua, &cmd.name)?;
|
||||||
let job = lua.create_table_from([
|
let job = lua.create_table_from([
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ pub fn spot(cmd: &'static Cmd, file: yazi_fs::File, mime: SStr, skip: usize) ->
|
||||||
Ok(VmState::Continue)
|
Ok(VmState::Continue)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
)?;
|
||||||
|
|
||||||
let plugin = LOADER.load_once(&lua, &cmd.name)?;
|
let plugin = LOADER.load_once(&lua, &cmd.name)?;
|
||||||
let job = lua.create_table_from([
|
let job = lua.create_table_from([
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,13 @@ impl From<Vec<u8>> for Chunk {
|
||||||
fn from(b: Vec<u8>) -> Self { Self::from(Cow::Owned(b)) }
|
fn from(b: Vec<u8>) -> Self { Self::from(Cow::Owned(b)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AsChunk<'a> for &'a Chunk {
|
impl AsChunk for &Chunk {
|
||||||
fn source(self) -> std::io::Result<Cow<'a, [u8]>> { Ok(Cow::Borrowed(&self.bytes)) }
|
|
||||||
|
|
||||||
fn mode(&self) -> Option<ChunkMode> { Some(self.mode) }
|
fn mode(&self) -> Option<ChunkMode> { Some(self.mode) }
|
||||||
|
|
||||||
|
fn source<'a>(&self) -> std::io::Result<Cow<'a, [u8]>>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
Ok(Cow::Borrowed(&self.bytes))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ impl Require {
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
let ts = lua.create_table_from([("__mod", r#mod)])?;
|
let ts = lua.create_table_from([("__mod", r#mod)])?;
|
||||||
ts.set_metatable(Some(mt));
|
ts.set_metatable(Some(mt))?;
|
||||||
Ok(ts)
|
Ok(ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ impl Command {
|
||||||
("INHERIT", INHERIT),
|
("INHERIT", INHERIT),
|
||||||
])?;
|
])?;
|
||||||
|
|
||||||
command.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
|
command.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
|
||||||
|
|
||||||
lua.globals().raw_set("Command", command)
|
lua.globals().raw_set("Command", command)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue