mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
27 lines
739 B
Rust
27 lines
739 B
Rust
use mlua::{ExternalError, ExternalResult, Table, TableExt};
|
|
use tokio::runtime::Handle;
|
|
|
|
use super::slim_lua;
|
|
use crate::{ValueSendable, LOADED};
|
|
|
|
pub async fn entry(name: String, args: Vec<ValueSendable>) -> mlua::Result<()> {
|
|
LOADED.ensure(&name).await.into_lua_err()?;
|
|
|
|
tokio::task::spawn_blocking(move || {
|
|
let lua = slim_lua()?;
|
|
let globals = lua.globals();
|
|
|
|
globals.raw_set("YAZI_PLUGIN_NAME", lua.create_string(&name)?)?;
|
|
globals.raw_set("YAZI_SYNC_CALLS", 0)?;
|
|
|
|
let plugin: Table = if let Some(b) = LOADED.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()?
|
|
}
|