feat: custom plugin config support

This commit is contained in:
YuKun Liu 2022-10-10 22:49:52 -07:00
parent e1497acef4
commit 96ebe74d12
2 changed files with 14 additions and 8 deletions

View file

@ -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<Lua> = 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();

View file

@ -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),