pub fn core_writeline(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "writeline requires two arguments");
            return 0;
        }

        let line_rr = self.stack.pop().unwrap();
        let line_rrb = line_rr.borrow();
        let line_str_pre = line_rrb.to_string();
        let line_str_opt = to_string_2(&line_str_pre);

        match line_str_opt {
            Some(s) => {
                if s != "" {
                    let file_writer = self.stack.pop().unwrap();
                    let mut file_writer_b = file_writer.borrow_mut();
                    match *file_writer_b {
                        Value::FileWriter(ref mut line_writer) => {
                            let res = line_writer.write_all(s.as_bytes());
                            match res {
                                Ok(_) => {
                                    return 1;
                                }
                                Err(e) => {
                                    let err_str = format!(
                                        "unable to open file: {}",
                                        e.to_string()
                                    );
                                    print_error(chunk, i, &err_str);
                                    return 0;
                                }
                            }
                        }
                        _ => {
                            print_error(
                                chunk,
                                i,
                                "writeline argument must be a file writer",
                            );
                            return 0;
                        }
                    }
                }
            }
            _ => {
                print_error(chunk, i, "writeline argument must be a string");
                return 0;
            }
        };
        return 1;
    }
/// Takes a FileWriter object and a line as its arguments.  Writes
/// the line to the file.
Takes a FileWriter object and a line as its arguments.  Writes
the line to the file.
Takes a FileWriter object and a line as its arguments . Writes the line to the file .
pub fn core_writeline(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 2 {
            print_error(chunk, i, "writeline requires two arguments");
            return 0;
        }
        let line_rr = self.stack.pop().unwrap();
        let line_rrb = line_rr.borrow();
        let line_str_pre = line_rrb.to_string();
        let line_str_opt = to_string_2(&line_str_pre);
        match line_str_opt {
            Some(s) => {
                if s != "" {
                    let file_writer = self.stack.pop().unwrap();
                    let mut file_writer_b = file_writer.borrow_mut();
                    match *file_writer_b {
                        Value::FileWriter(ref mut line_writer) => {
                            let res = line_writer.write_all(s.as_bytes());
                            match res {
                                Ok(_) => {
                                    return 1;
                                }
                                Err(e) => {
                                    let err_str = format!(
                                        "unable to open file: {}",
                                        e.to_string()
                                    );
                                    print_error(chunk, i, &err_str);
                                    return 0;
                                }
                            }
                        }
                        _ => {
                            print_error(
                                chunk,
                                i,
                                "writeline argument must be a file writer",
                            );
                            return 0;
                        }
                    }
                }
            }
            _ => {
                print_error(chunk, i, "writeline argument must be a string");
                return 0;
            }
        };
        return 1;
    }
pub fn core_writeline ( & mut self , chunk : & Chunk , i : usize ) -> i32 { if self . stack . len ( ) < 2 { print_error ( chunk , i , " " ) ; return 0 ; } let line_rr = self . stack . pop ( ) . unwrap ( ) ; let line_rrb = line_rr . borrow ( ) ; let line_str_pre = line_rrb . to_string ( ) ; let line_str_opt = to_string_2 ( & line_str_pre ) ; match line_str_opt { Some ( s ) => { if s != " " { let file_writer = self . stack . pop ( ) . unwrap ( ) ; let mut file_writer_b = file_writer . borrow_mut ( ) ; match * file_writer_b { Value :: FileWriter ( ref mut line_writer ) => { let res = line_writer . write_all ( s . as_bytes ( ) ) ; match res { Ok ( _ ) => { return 1 ; } Err ( e ) => { let err_str = format ! ( " " e to_string ( ) ) ; print_error ( chunk , i , & err_str ) ; return 0 ; } } } _ => { print_error ( chunk , i , " " , ) ; return 0 ; } } } } _ => { print_error ( chunk , i , " " ) ; return 0 ; } } ; return 1 ; }
Takes a FileWriter object and a line as its arguments.
Takes a FileWriter object and a line as its arguments .
&mut self
chunk
&Chunk
i
usize