refactor: upgrade to mlua v0.11.0 (#2989)

This commit is contained in:
三咲雅 misaki masa 2025-07-16 11:02:34 +08:00 committed by GitHub
parent 60a2382087
commit 548bb0d063
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 50 additions and 36 deletions

31
Cargo.lock generated
View file

@ -1247,6 +1247,15 @@ dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.15"
@ -1394,18 +1403,18 @@ dependencies = [
[[package]]
name = "lua-src"
version = "547.0.0"
version = "548.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1edaf29e3517b49b8b746701e5648ccb5785cde1c119062cbabbc5d5cd115e42"
checksum = "00bc4bd1f1d5c65b30717333cbec4fa7aa378978940a1bca62f404498d423233"
dependencies = [
"cc",
]
[[package]]
name = "luajit-src"
version = "210.5.12+a4f56a4"
version = "210.6.1+f9140a6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3a8e7962a5368d5f264d045a5a255e90f9aa3fc1941ae15a8d2940d42cac671"
checksum = "813bd31f2759443affa687c0d9c5eb5cf6cb0e898810ab197408431d746054bf"
dependencies = [
"cc",
"which",
@ -1474,9 +1483,9 @@ dependencies = [
[[package]]
name = "mlua"
version = "0.10.5"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1f5f8fbebc7db5f671671134b9321c4b9aa9adeafccfd9a8c020ae45c6a35d0"
checksum = "de25fc513588ac1273aa8c6dc0fffee6d32c12f38dc75f5cdc74547121a107ef"
dependencies = [
"anyhow",
"bstr",
@ -1495,9 +1504,9 @@ dependencies = [
[[package]]
name = "mlua-sys"
version = "0.6.8"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "380c1f7e2099cafcf40e51d3a9f20a346977587aa4d012eae1f043149a728a93"
checksum = "bcdf7c9e260ca82aaa32ac11148941952b856bb8c69aa5a9e65962f21fcb8637"
dependencies = [
"cc",
"cfg-if",
@ -1508,11 +1517,11 @@ dependencies = [
[[package]]
name = "mlua_derive"
version = "0.10.1"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "870d71c172fcf491c6b5fb4c04160619a2ee3e5a42a1402269c66bcbf1dd4deb"
checksum = "465bddde514c4eb3b50b543250e97c1d4b284fa3ef7dc0ba2992c77545dbceb2"
dependencies = [
"itertools 0.13.0",
"itertools 0.14.0",
"once_cell",
"proc-macro-error2",
"proc-macro2",

View file

@ -34,7 +34,7 @@ globset = "0.4.16"
indexmap = { version = "2.10.0", features = [ "serde" ] }
libc = "0.2.174"
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"
ordered-float = { version = "5.0.0", features = [ "serde" ] }
parking_lot = "0.12.4"

View file

@ -18,7 +18,7 @@ impl Bar {
lua.create_function(|_, (_, edge): (Table, Edge)| Ok(Self { edge, ..Default::default() }))?;
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)
}

View file

@ -38,7 +38,7 @@ impl Border {
("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)
}

View file

@ -17,7 +17,7 @@ impl Clear {
let new = lua.create_function(|_, (_, area): (Table, Area)| Ok(Clear { area }))?;
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)
}

View file

@ -19,7 +19,7 @@ impl Gauge {
let new = lua.create_function(|_, _: Table| Ok(Gauge::default()))?;
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)
}

View file

@ -17,7 +17,7 @@ impl Layout {
let new = lua.create_function(|_, _: Table| Ok(Self::default()))?;
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)
}

View file

@ -36,7 +36,7 @@ impl Line {
})?;
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)
}

View file

@ -25,7 +25,7 @@ impl List {
})?;
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)
}

View file

@ -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)
}
}

View file

@ -70,7 +70,7 @@ impl Pos {
let new = lua.create_function(|_, (_, t): (Table, Table)| Self::try_from(t))?;
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)
}
@ -85,7 +85,7 @@ impl Pos {
impl UserData for Pos {
fn add_fields<F: mlua::UserDataFields<Self>>(fields: &mut F) {
// 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("y", |_, me| Ok(me.offset.y));
fields.add_field_method_get("w", |_, me| Ok(me.offset.width));

View file

@ -48,7 +48,7 @@ impl Rect {
let rect = lua.create_table()?;
rect.set_metatable(Some(
lua.create_table_from([(MetaMethod::Call.name(), new), (MetaMethod::Index.name(), index)])?,
));
))?;
rect.into_lua(lua)
}

View file

@ -20,7 +20,7 @@ impl Row {
})?;
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)
}

View file

@ -12,7 +12,7 @@ impl Span {
let new = lua.create_function(|_, (_, value): (Table, Value)| Span::try_from(value))?;
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)
}

View file

@ -43,7 +43,7 @@ impl 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)
}

View file

@ -28,7 +28,7 @@ impl Text {
})?;
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)
}

View file

@ -8,7 +8,7 @@ impl Style {
let new = lua.create_function(|_, (_, value): (Table, Value)| Self::try_from(value))?;
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)
}

View file

@ -81,7 +81,7 @@ fn peek_async(
Ok(VmState::Continue)
}
},
);
)?;
let plugin = LOADER.load_once(&lua, &cmd.name)?;
let job = lua.create_table_from([

View file

@ -29,7 +29,7 @@ pub async fn preload(
Ok(VmState::Continue)
}
},
);
)?;
let plugin = LOADER.load_once(&lua, &cmd.name)?;
let job = lua.create_table_from([

View file

@ -29,7 +29,7 @@ pub fn spot(cmd: &'static Cmd, file: yazi_fs::File, mime: SStr, skip: usize) ->
Ok(VmState::Continue)
}
},
);
)?;
let plugin = LOADER.load_once(&lua, &cmd.name)?;
let job = lua.create_table_from([

View file

@ -65,8 +65,13 @@ impl From<Vec<u8>> for Chunk {
fn from(b: Vec<u8>) -> Self { Self::from(Cow::Owned(b)) }
}
impl<'a> AsChunk<'a> for &'a Chunk {
fn source(self) -> std::io::Result<Cow<'a, [u8]>> { Ok(Cow::Borrowed(&self.bytes)) }
impl AsChunk for &Chunk {
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))
}
}

View file

@ -63,7 +63,7 @@ impl Require {
])?;
let ts = lua.create_table_from([("__mod", r#mod)])?;
ts.set_metatable(Some(mt));
ts.set_metatable(Some(mt))?;
Ok(ts)
}

View file

@ -33,7 +33,7 @@ impl Command {
("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)
}