fix: move is_dir & is_file to path
This commit is contained in:
1 parent
1c59c902a6
commit
b59e41eaee
2 files changed
+21
-9
No files matched your search
@@ -14,14 +14,6 @@ impl UserData for PluginFileSystem {
|
|||||||
let path = PathBuf::from(path);
|
let path = PathBuf::from(path);
|
||||||
Ok(path.exists())
|
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())
|
|
||||||
});
|
|
||||||
methods.add_function("create_dir", |_, args: (String, bool)| {
|
methods.add_function("create_dir", |_, args: (String, bool)| {
|
||||||
let path = args.0;
|
let path = args.0;
|
||||||
let recursive = args.1;
|
let recursive = args.1;
|
||||||
|
|||||||
@@ -5,10 +5,30 @@ use mlua::UserData;
|
|||||||
pub struct PluginPath;
|
pub struct PluginPath;
|
||||||
impl UserData for PluginPath {
|
impl UserData for PluginPath {
|
||||||
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
fn add_methods<'lua, M: mlua::UserDataMethods<'lua, Self>>(methods: &mut M) {
|
||||||
|
// join function
|
||||||
methods.add_function("join", |_, args: (String, String)| {
|
methods.add_function("join", |_, args: (String, String)| {
|
||||||
let current_path = PathBuf::from(args.0);
|
let current_path = PathBuf::from(args.0);
|
||||||
let new_path = current_path.join(args.1);
|
let new_path = current_path.join(args.1);
|
||||||
Ok(new_path.to_str().unwrap().to_string())
|
Ok(new_path.to_str().unwrap().to_string())
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// parent function
|
||||||
|
methods.add_function("parent", |_, path: String| {
|
||||||
|
let current_path = PathBuf::from(&path);
|
||||||
|
let parent = current_path.parent();
|
||||||
|
if parent.is_none() {
|
||||||
|
return Ok(path);
|
||||||
|
} else {
|
||||||
|
return Ok(parent.unwrap().to_str().unwrap().to_string());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
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())
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user