mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
23 lines
614 B
Rust
23 lines
614 B
Rust
use mlua::{ExternalError, ExternalResult, Table, TableExt};
|
|
use tokio::runtime::Handle;
|
|
use yazi_dds::ValueSendable;
|
|
|
|
use super::slim_lua;
|
|
use crate::LOADER;
|
|
|
|
pub async fn entry(name: String, args: Vec<ValueSendable>) -> mlua::Result<()> {
|
|
LOADER.ensure(&name).await.into_lua_err()?;
|
|
|
|
tokio::task::spawn_blocking(move || {
|
|
let lua = slim_lua(&name)?;
|
|
let plugin: Table = if let Some(b) = LOADER.read().get(&name) {
|
|
lua.load(b).call(())?
|
|
} else {
|
|
return Err("unloaded plugin".into_lua_err());
|
|
};
|
|
|
|
Handle::current().block_on(plugin.call_async_method("entry", args))
|
|
})
|
|
.await
|
|
.into_lua_err()?
|
|
}
|