pub fn opcode_readline(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 1 {
            print_error(chunk, i, "readline requires one argument");
            return 0;
        }

        let file_reader_rr = self.stack.pop().unwrap();
        let mut file_reader_rrb = file_reader_rr.borrow_mut();

        match *file_reader_rrb {
            Value::FileReader(ref mut bufread) => {
                let mut contents = String::new();
                let res = BufRead::read_line(bufread, &mut contents);
                match res {
                    Ok(0) => {
                        self.stack.push(Rc::new(RefCell::new(Value::Null)));
                    }
                    Ok(_) => {
                        self.stack.push(Rc::new(RefCell::new(Value::String(
                            contents, None,
                        ))));
                    }
                    _ => {
                        print_error(chunk, i, "unable to read line from file");
                        return 0;
                    }
                }
            }
            _ => {
                print_error(
                    chunk,
                    i,
                    "readline argument must be a file reader",
                );
                return 0;
            }
        }
        return 1;
    }
/// Takes a FileReader object as its single argument.  Reads one
/// line from that object and places it onto the stack (including
/// the ending newline).
Takes a FileReader object as its single argument.  Reads one
line from that object and places it onto the stack (including
the ending newline).
Takes a FileReader object as its single argument . Reads one line from that object and places it onto the stack ( including the ending newline ) .
pub fn opcode_readline(&mut self, chunk: &Chunk, i: usize) -> i32 {
        if self.stack.len() < 1 {
            print_error(chunk, i, "readline requires one argument");
            return 0;
        }
        let file_reader_rr = self.stack.pop().unwrap();
        let mut file_reader_rrb = file_reader_rr.borrow_mut();
        match *file_reader_rrb {
            Value::FileReader(ref mut bufread) => {
                let mut contents = String::new();
                let res = BufRead::read_line(bufread, &mut contents);
                match res {
                    Ok(0) => {
                        self.stack.push(Rc::new(RefCell::new(Value::Null)));
                    }
                    Ok(_) => {
                        self.stack.push(Rc::new(RefCell::new(Value::String(
                            contents, None,
                        ))));
                    }
                    _ => {
                        print_error(chunk, i, "unable to read line from file");
                        return 0;
                    }
                }
            }
            _ => {
                print_error(
                    chunk,
                    i,
                    "readline argument must be a file reader",
                );
                return 0;
            }
        }
        return 1;
    }
pub fn opcode_readline ( & mut self , chunk : & Chunk , i : usize ) -> i32 { if self . stack . len ( ) < 1 { print_error ( chunk , i , " " ) ; return 0 ; } let file_reader_rr = self . stack . pop ( ) . unwrap ( ) ; let mut file_reader_rrb = file_reader_rr . borrow_mut ( ) ; match * file_reader_rrb { Value :: FileReader ( ref mut bufread ) => { let mut contents = String :: new ( ) ; let res = BufRead :: read_line ( bufread , & mut contents ) ; match res { Ok ( 0 ) => { self . stack . push ( Rc :: new ( RefCell :: new ( Value :: Null ) ) ) ; } Ok ( _ ) => { self . stack . push ( Rc :: new ( RefCell :: new ( Value :: String ( contents , None , ) ) ) ) ; } _ => { print_error ( chunk , i , " " ) ; return 0 ; } } } _ => { print_error ( chunk , i , " " , ) ; return 0 ; } } return 1 ; }
Takes a FileReader object as its single argument.
Takes a FileReader object as its single argument .
&mut self
chunk
&Chunk
i
usize