pub fn core_cd(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() == 0 {
            let home_res = std::env::var("HOME");
            match home_res {
                Ok(home) => {
                    let res = env::set_current_dir(&home);
                    match res {
                        Ok(_) => {}
                        Err(e) => {
                            let err_str = format!(
                                "unable to cd to home: {}",
                                e.to_string()
                            );
                            print_error(chunk, i, &err_str);
                            return 0;
                        }
                    }
                }
                Err(e) => {
                    let err_str =
                        format!("unable to cd to home: {}", e.to_string());
                    print_error(chunk, i, &err_str);
                    return 0;
                }
            }
        } else {
            let dir_rr = self.stack.pop().unwrap();
            let dir_rrb = dir_rr.borrow();
            let dir_pre = dir_rrb.to_string();
            let dir_opt = to_string_2(&dir_pre);

            match dir_opt {
                Some(dir) => {
                    let path_dir = Path::new(&dir);
                    let res = env::set_current_dir(&path_dir);
                    match res {
                        Ok(_) => {}
                        Err(e) => {
                            let err_str =
                                format!("unable to cd: {}", e.to_string());
                            print_error(chunk, i, &err_str);
                            return 0;
                        }
                    }
                }
                _ => {
                    print_error(chunk, i, "cd argument must be a string");
                    return 0;
                }
            }
        }
        return 1;
    }
/// Takes a value that can be stringified as its single argument.
/// Changes the current working directory to that directory.  If
/// no arguments are provided, then this changes the current
/// working directory to the user's home directory.
Takes a value that can be stringified as its single argument.
Changes the current working directory to that directory.  If
no arguments are provided, then this changes the current
working directory to the user's home directory.
Takes a value that can be stringified as its single argument . Changes the current working directory to that directory . If no arguments are provided then this changes the current working directory to the user ' s home directory .
pub fn core_cd(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() == 0 {
            let home_res = std::env::var("HOME");
            match home_res {
                Ok(home) => {
                    let res = env::set_current_dir(&home);
                    match res {
                        Ok(_) => {}
                        Err(e) => {
                            let err_str = format!(
                                "unable to cd to home: {}",
                                e.to_string()
                            );
                            print_error(chunk, i, &err_str);
                            return 0;
                        }
                    }
                }
                Err(e) => {
                    let err_str =
                        format!("unable to cd to home: {}", e.to_string());
                    print_error(chunk, i, &err_str);
                    return 0;
                }
            }
        } else {
            let dir_rr = self.stack.pop().unwrap();
            let dir_rrb = dir_rr.borrow();
            let dir_pre = dir_rrb.to_string();
            let dir_opt = to_string_2(&dir_pre);
            match dir_opt {
                Some(dir) => {
                    let path_dir = Path::new(&dir);
                    let res = env::set_current_dir(&path_dir);
                    match res {
                        Ok(_) => {}
                        Err(e) => {
                            let err_str =
                                format!("unable to cd: {}", e.to_string());
                            print_error(chunk, i, &err_str);
                            return 0;
                        }
                    }
                }
                _ => {
                    print_error(chunk, i, "cd argument must be a string");
                    return 0;
                }
            }
        }
        return 1;
    }
pub fn core_cd ( & mut self , chunk : & Chunk , i : usize ) -> i32 { if self . stack . len ( ) == 0 { let home_res = std :: env :: var ( " " ) ; match home_res { Ok ( home ) => { let res = env :: set_current_dir ( & home ) ; match res { Ok ( _ ) => { } Err ( e ) => { let err_str = format ! ( " " e to_string ( ) ) ; print_error ( chunk , i , & err_str ) ; return 0 ; } } } Err ( e ) => { let err_str = format ! ( " " e to_string ( ) ) ; print_error ( chunk , i , & err_str ) ; return 0 ; } } } else { let dir_rr = self . stack . pop ( ) . unwrap ( ) ; let dir_rrb = dir_rr . borrow ( ) ; let dir_pre = dir_rrb . to_string ( ) ; let dir_opt = to_string_2 ( & dir_pre ) ; match dir_opt { Some ( dir ) => { let path_dir = Path :: new ( & dir ) ; let res = env :: set_current_dir ( & path_dir ) ; match res { Ok ( _ ) => { } Err ( e ) => { let err_str = format ! ( " " e to_string ( ) ) ; print_error ( chunk , i , & err_str ) ; return 0 ; } } } _ => { print_error ( chunk , i , " " ) ; return 0 ; } } } return 1 ; }
Takes a value that can be stringified as its single argument.
Takes a value that can be stringified as its single argument .
&mut self
chunk
&Chunk
i
usize