feat: commit code
This commit is contained in:
1 parent
2065193b63
commit
59acefadc9
4 files changed
+34
-32
No files matched your search
@@ -59,27 +59,6 @@ impl UserData for PluginCommander {
|
|||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
methods.add_function("execQuiet", |_, cmd: Vec<String>| {
|
|
||||||
if cmd.len() == 0 {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
let cmd_name = cmd.get(0).unwrap();
|
|
||||||
let mut command = Command::new(cmd_name);
|
|
||||||
let t = cmd
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.filter(|(i, _)| *i > 0)
|
|
||||||
.map(|v| v.1.clone())
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
command.args(t);
|
|
||||||
command.stdout(Stdio::null());
|
|
||||||
command.output()?;
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
methods.add_function("execSimple", |_, cmd: String| {
|
|
||||||
let _ = Command::new(cmd).stdout(Stdio::inherit()).output()?;
|
|
||||||
Ok(())
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_fields<'lua, F: mlua::UserDataFields<'lua, Self>>(_fields: &mut F) {}
|
fn add_fields<'lua, F: mlua::UserDataFields<'lua, Self>>(_fields: &mut F) {}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use mlua::UserData;
|
||||||
|
|
||||||
|
pub struct PluginFileSystem;
|
||||||
|
impl UserData for PluginFileSystem {
|
||||||
|
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
|
methods.add_function("exists", |_, path: String| {
|
||||||
|
let path = PathBuf::from(path);
|
||||||
|
Ok(path.exists())
|
||||||
|
});
|
||||||
|
methods.add_function("is_dir", |_, path: String| {
|
||||||
|
let path = PathBuf::from(path);
|
||||||
|
Ok(path.is_dir())
|
||||||
|
});
|
||||||
|
methods.add_function("is_file", |_, path: String| {
|
||||||
|
let path = PathBuf::from(path);
|
||||||
|
Ok(path.is_file())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ use mlua::{FromLua, Function, ToLua};
|
|||||||
|
|
||||||
pub mod logger;
|
pub mod logger;
|
||||||
pub mod command;
|
pub mod command;
|
||||||
|
pub mod fs;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct PluginInfo<'lua> {
|
pub struct PluginInfo<'lua> {
|
||||||
@@ -38,16 +39,16 @@ impl<'lua> FromLua<'lua> for PluginInfo<'lua> {
|
|||||||
res.author = v;
|
res.author = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(v) = tab.get::<_, Function>("onInit") {
|
if let Ok(v) = tab.get::<_, Function>("on_init") {
|
||||||
res.on_init = Some(v);
|
res.on_init = Some(v);
|
||||||
}
|
}
|
||||||
if let Ok(v) = tab.get::<_, Function>("onLoad") {
|
if let Ok(v) = tab.get::<_, Function>("on_load") {
|
||||||
res.on_load = Some(v);
|
res.on_load = Some(v);
|
||||||
}
|
}
|
||||||
if let Ok(v) = tab.get::<_, Function>("onBuildStart") {
|
if let Ok(v) = tab.get::<_, Function>("on_build_start") {
|
||||||
res.on_build_start = Some(v);
|
res.on_build_start = Some(v);
|
||||||
}
|
}
|
||||||
if let Ok(v) = tab.get::<_, Function>("onBuildFinish") {
|
if let Ok(v) = tab.get::<_, Function>("on_build_finish") {
|
||||||
res.on_build_finish = Some(v);
|
res.on_build_finish = Some(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,16 +68,16 @@ impl<'lua> ToLua<'lua> for PluginInfo<'lua> {
|
|||||||
res.set("author", self.author.to_string())?;
|
res.set("author", self.author.to_string())?;
|
||||||
|
|
||||||
if let Some(e) = self.on_init {
|
if let Some(e) = self.on_init {
|
||||||
res.set("onInit", e)?;
|
res.set("on_init", e)?;
|
||||||
}
|
}
|
||||||
if let Some(e) = self.on_load {
|
if let Some(e) = self.on_load {
|
||||||
res.set("onLoad", e)?;
|
res.set("on_load", e)?;
|
||||||
}
|
}
|
||||||
if let Some(e) = self.on_build_start {
|
if let Some(e) = self.on_build_start {
|
||||||
res.set("onBuildStart", e)?;
|
res.set("on_build_start", e)?;
|
||||||
}
|
}
|
||||||
if let Some(e) = self.on_build_finish {
|
if let Some(e) = self.on_build_finish {
|
||||||
res.set("onBuildFinish", e)?;
|
res.set("on_build_finish", e)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(mlua::Value::Table(res))
|
Ok(mlua::Value::Table(res))
|
||||||
|
|||||||
+4
-3
@@ -7,7 +7,7 @@ use crate::tools::{app_path, clone_repo};
|
|||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
interface::PluginInfo,
|
interface::PluginInfo,
|
||||||
interface::{command::PluginCommander, logger::PluginLogger},
|
interface::{command::PluginCommander, logger::PluginLogger, fs::PluginFileSystem},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod interface;
|
pub mod interface;
|
||||||
@@ -32,10 +32,11 @@ impl PluginManager {
|
|||||||
|
|
||||||
let manager = lua.create_table().unwrap();
|
let manager = lua.create_table().unwrap();
|
||||||
|
|
||||||
lua.globals().set("plugin_logger", PluginLogger).unwrap();
|
lua.globals().set("PLUGIN_LOGGER", PluginLogger).unwrap();
|
||||||
lua.globals()
|
lua.globals()
|
||||||
.set("plugin_commander", PluginCommander)
|
.set("PLUGIN_COMMAND", PluginCommander)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
lua.globals().set("PLUGINFS", PluginFileSystem).unwrap();
|
||||||
|
|
||||||
let plugin_dir = Self::init_plugin_dir();
|
let plugin_dir = Self::init_plugin_dir();
|
||||||
let mut index = 1;
|
let mut index = 1;
|
||||||
|
|||||||
Reference in new issue
Block a user