Skip to content

Commit

Permalink
Implemented chdir bindings for #170
Browse files Browse the repository at this point in the history
Note: It might be best to move this binding out of `fs` and maybe into something specific for the system.
  • Loading branch information
dariusc93 committed Dec 19, 2018
1 parent aaefb1d commit 0215608
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/bindings/system/fs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rlua::prelude::*;
use std::sync::Arc;
use std::env;
use std::fs;
use serde_json;
use rlua_serde;
Expand Down Expand Up @@ -63,6 +64,10 @@ pub fn init(lua: &Lua) -> ::Result<()> {
Ok(lua.create_string(&String::from_utf8_lossy(&data[..]).to_owned().to_string())?)
})?)?;

module.set("chdir", lua.create_function(|_, path: String| {
env::set_current_dir(path).map_err(LuaError::external)
})?)?;

module.set("exists", lua.create_function( |_, path: String| {
Ok(::std::path::Path::new(&path).exists())
})?)?;
Expand Down

0 comments on commit 0215608

Please sign in to comment.