Skip to content

Commit

Permalink
fix: added "send" feature to mlua
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Oct 26, 2024
1 parent bdce8df commit 49cef81
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ homedir = "0.3"
indexmap = "2"
itertools = "0.13"
log = "0.4"
mlua = { version = "0.10", features = ["async", "lua54", "macros", "serialize", "vendored"] }
mlua = { version = "0.10", features = ["async", "lua54", "macros", "serialize", "vendored", "send"] }
once_cell = "1"
reqwest = { version = "0.12", features = [] } # TODO: replace with xx
scraper = "0.20"
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/parse_legacy_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use mlua::{FromLua, IntoLua, Lua, MultiValue, Value};
use std::path::{Path, PathBuf};

use crate::error::Result;
use crate::plugin::AppData;
use crate::Plugin;

#[derive(Debug)]
Expand Down Expand Up @@ -44,8 +43,8 @@ impl IntoLua for LegacyFileContext {
table.set(
"getInstalledVersions",
lua.create_async_function(|lua, _input: MultiValue| async move {
let app_data = lua.app_data_ref::<AppData>().unwrap();
Ok(Plugin::from_dir(app_data.plugin_dir.as_path())
let plugin_dir = lua.named_registry_value::<PathBuf>("plugin_dir")?;
Ok(Plugin::from_dir(plugin_dir.as_path())
.map_err(|e| LuaError::RuntimeError(e.to_string()))?
.available_async()
.await
Expand Down
9 changes: 1 addition & 8 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,13 @@ pub struct Plugin {
metadata: OnceCell<Metadata>,
}

#[derive(Debug)]
pub struct AppData {
pub(crate) plugin_dir: PathBuf,
}

impl Plugin {
pub fn from_dir(dir: &Path) -> Result<Self> {
if !dir.exists() {
error!("Plugin directory not found: {:?}", dir);
}
let lua = Lua::new();
lua.set_app_data(AppData {
plugin_dir: dir.to_path_buf(),
});
lua.set_named_registry_value("plugin_dir", dir.to_path_buf())?;
Ok(Self {
name: dir.file_name().unwrap().to_string_lossy().to_string(),
dir: dir.to_path_buf(),
Expand Down

0 comments on commit 49cef81

Please sign in to comment.