Add tempdir support
This commit is contained in:
@@ -98,6 +98,14 @@ impl lb_fslib {
|
||||
prefix,
|
||||
})
|
||||
}
|
||||
|
||||
pub extern "Lua-C" fn temp_dir(&self) -> Result<lb_temp_dir> {
|
||||
Ok(tempfile::tempdir()?.into())
|
||||
}
|
||||
|
||||
pub extern "Lua-C" fn temp_dir_in(&self, path: &str) -> Result<lb_temp_dir> {
|
||||
Ok(tempfile::tempdir_in(path)?.into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator over the entries in a directory.
|
||||
@@ -401,3 +409,20 @@ impl lb_glob_dir {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Directory in the filesystem that is automatically deleted when it is garbage-collected.
|
||||
#[derive(Debug, From)]
|
||||
#[cdef]
|
||||
pub struct lb_temp_dir(#[opaque] tempfile::TempDir);
|
||||
|
||||
#[metatype]
|
||||
impl lb_temp_dir {
|
||||
pub extern "Lua-C" fn path(&self) -> String {
|
||||
self.0.path().to_string_lossy().into()
|
||||
}
|
||||
|
||||
#[tostring]
|
||||
pub extern "Lua" fn tostring(&self) -> String {
|
||||
self.path()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user