stdin: add ability to provide a reader for stdin
This commit is contained in:
parent
6ef9bee1b7
commit
3f83afe287
|
@ -4,6 +4,7 @@ package gofuck
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
@ -19,12 +20,16 @@ type Machine struct {
|
|||
}
|
||||
|
||||
// Returns a new machine with standard memory size
|
||||
func New() *Machine {
|
||||
func NewStdin() *Machine {
|
||||
return New(os.Stdin)
|
||||
}
|
||||
|
||||
func New(in io.Reader) *Machine {
|
||||
bytes := make([]byte, MEM_STD)
|
||||
return &Machine{
|
||||
array: bytes,
|
||||
ptr: 0,
|
||||
reader: bufio.NewReader(os.Stdin),
|
||||
reader: bufio.NewReader(in),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
m := gofuck.New()
|
||||
m := gofuck.NewStdin()
|
||||
instructions := make([]byte, 0)
|
||||
|
||||
// read in the instructions
|
||||
|
|
Loading…
Reference in New Issue