...
This commit is contained in:
@@ -31,6 +31,9 @@ pub fn register_os_module(engine: &mut Engine) -> Result<(), Box<EvalAltResult>>
|
||||
engine.register_fn("file_size", file_size);
|
||||
engine.register_fn("rsync", rsync);
|
||||
engine.register_fn("chdir", chdir);
|
||||
engine.register_fn("file_read", file_read);
|
||||
engine.register_fn("file_write", file_write);
|
||||
engine.register_fn("file_write_append", file_write_append);
|
||||
|
||||
// Register download functions
|
||||
engine.register_fn("download", download);
|
||||
@@ -136,6 +139,27 @@ pub fn chdir(path: &str) -> Result<String, Box<EvalAltResult>> {
|
||||
os::chdir(path).to_rhai_error()
|
||||
}
|
||||
|
||||
/// Wrapper for os::file_read
|
||||
///
|
||||
/// Read the contents of a file.
|
||||
pub fn file_read(path: &str) -> Result<String, Box<EvalAltResult>> {
|
||||
os::file_read(path).to_rhai_error()
|
||||
}
|
||||
|
||||
/// Wrapper for os::file_write
|
||||
///
|
||||
/// Write content to a file (creates the file if it doesn't exist, overwrites if it does).
|
||||
pub fn file_write(path: &str, content: &str) -> Result<String, Box<EvalAltResult>> {
|
||||
os::file_write(path, content).to_rhai_error()
|
||||
}
|
||||
|
||||
/// Wrapper for os::file_write_append
|
||||
///
|
||||
/// Append content to a file (creates the file if it doesn't exist).
|
||||
pub fn file_write_append(path: &str, content: &str) -> Result<String, Box<EvalAltResult>> {
|
||||
os::file_write_append(path, content).to_rhai_error()
|
||||
}
|
||||
|
||||
//
|
||||
// Download Function Wrappers
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user