mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
feat: allow overriding and rewriting the sync methods of builtin plugins (#1695)
This commit is contained in:
parent
70fbe41cc2
commit
3e4973dbbf
2 changed files with 22 additions and 14 deletions
8
.github/ISSUE_TEMPLATE/feature.yml
vendored
8
.github/ISSUE_TEMPLATE/feature.yml
vendored
|
|
@ -43,7 +43,7 @@ body:
|
|||
label: Validations
|
||||
description: Before submitting the issue, please make sure you have completed the following
|
||||
options:
|
||||
- label: I have searched the existing issues
|
||||
required: true
|
||||
- label: The latest nightly build of Yazi doesn't already have this feature
|
||||
required: true
|
||||
- label: I have searched the existing issues/discussions
|
||||
required: true
|
||||
- label: The latest nightly build of Yazi doesn't already have this feature
|
||||
required: true
|
||||
|
|
|
|||
|
|
@ -42,17 +42,25 @@ impl Require {
|
|||
|
||||
fn create_mt<'a>(lua: &'a Lua, id: &str, mod_: Table<'a>, sync: bool) -> mlua::Result<Table<'a>> {
|
||||
let id: Arc<str> = Arc::from(id);
|
||||
let mt = lua.create_table_from([(
|
||||
"__index",
|
||||
lua.create_function(move |lua, (ts, key): (Table, mlua::String)| {
|
||||
match ts.raw_get::<_, Table>("__mod")?.raw_get::<_, Value>(&key)? {
|
||||
Value::Function(_) => {
|
||||
Self::create_wrapper(lua, id.clone(), key.to_str()?, sync)?.into_lua(lua)
|
||||
let mt = lua.create_table_from([
|
||||
(
|
||||
"__index",
|
||||
lua.create_function(move |lua, (ts, key): (Table, mlua::String)| {
|
||||
match ts.raw_get::<_, Table>("__mod")?.raw_get::<_, Value>(&key)? {
|
||||
Value::Function(_) => {
|
||||
Self::create_wrapper(lua, id.clone(), key.to_str()?, sync)?.into_lua(lua)
|
||||
}
|
||||
v => Ok(v),
|
||||
}
|
||||
v => Ok(v),
|
||||
}
|
||||
})?,
|
||||
)])?;
|
||||
})?,
|
||||
),
|
||||
(
|
||||
"__newindex",
|
||||
lua.create_function(move |_, (ts, key, value): (Table, mlua::String, Value)| {
|
||||
ts.raw_get::<_, Table>("__mod")?.raw_set(key, value)
|
||||
})?,
|
||||
),
|
||||
])?;
|
||||
|
||||
let ts = lua.create_table_from([("__mod", mod_)])?;
|
||||
ts.set_metatable(Some(mt));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue