From 96ebe74d121a27e34c706240d4d645110d44b167 Mon Sep 17 00:00:00 2001 From: YuKun Liu Date: Mon, 10 Oct 2022 22:49:52 -0700 Subject: [PATCH] feat: custom plugin config support --- src/plugin/mod.rs | 7 ++++--- src/plugin/types.rs | 15 ++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 55e8883de..673f2ad5b 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -18,10 +18,11 @@ use self::{ command::PluginCommander, dirs::PluginDirs, fs::PluginFileSystem, log::PluginLogger, network::PluginNetwork, os::PluginOS, path::PluginPath, }, + types::PluginConfig, }; -mod types; pub mod interface; +mod types; lazy_static::lazy_static! { static ref LUA: Mutex = Mutex::new(Lua::new()); @@ -50,8 +51,8 @@ impl PluginManager { lua.globals() .set("library_dir", plugin_dir.to_str().unwrap()) .unwrap(); - // lua.globals() - // .set("config_info", ); + let config = PluginConfig::from_toml_value(config); + lua.globals().set("config_info", config)?; let mut index: u32 = 1; let mut init_list: Vec<(u32, PathBuf, PluginInfo)> = Vec::new(); diff --git a/src/plugin/types.rs b/src/plugin/types.rs index 181e09ddc..a73a09bf0 100644 --- a/src/plugin/types.rs +++ b/src/plugin/types.rs @@ -2,8 +2,6 @@ use std::collections::HashMap; use mlua::ToLua; -use super::LUA; - #[derive(Debug, Clone)] pub struct PluginConfig { available: bool, @@ -38,9 +36,15 @@ impl PluginConfig { let mut config_info = HashMap::new(); - let lua = LUA.lock().unwrap(); - - for (name, value) in tab {} + for (name, value) in tab { + if let toml::Value::Table(value) = value { + let mut map = HashMap::new(); + for (item, info) in value { + map.insert(item, Value::from_toml(info)); + } + config_info.insert(name, map); + } + } Self { available, @@ -55,6 +59,7 @@ impl PluginConfig { } } +#[allow(dead_code)] #[derive(Debug, Clone)] pub enum Value { String(String),