Skip to content

Commit

Permalink
feat: allow overriding and rewriting the sync methods of builtin plug…
Browse files Browse the repository at this point in the history
…ins (#1695)
  • Loading branch information
sxyazi authored Sep 27, 2024
1 parent 70fbe41 commit 3e4973d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 18 additions & 10 deletions yazi-plugin/src/loader/require.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 3e4973d

Please sign in to comment.