Skip to content

Commit 0215608

Browse files
committed
Implemented chdir bindings for #170
Note: It might be best to move this binding out of `fs` and maybe into something specific for the system.
1 parent aaefb1d commit 0215608

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/bindings/system/fs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rlua::prelude::*;
22
use std::sync::Arc;
3+
use std::env;
34
use std::fs;
45
use serde_json;
56
use rlua_serde;
@@ -63,6 +64,10 @@ pub fn init(lua: &Lua) -> ::Result<()> {
6364
Ok(lua.create_string(&String::from_utf8_lossy(&data[..]).to_owned().to_string())?)
6465
})?)?;
6566

67+
module.set("chdir", lua.create_function(|_, path: String| {
68+
env::set_current_dir(path).map_err(LuaError::external)
69+
})?)?;
70+
6671
module.set("exists", lua.create_function( |_, path: String| {
6772
Ok(::std::path::Path::new(&path).exists())
6873
})?)?;

0 commit comments

Comments
 (0)