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 (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,12 +20,16 @@ type Machine struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a new machine with standard memory size
|
// 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)
|
bytes := make([]byte, MEM_STD)
|
||||||
return &Machine{
|
return &Machine{
|
||||||
array: bytes,
|
array: bytes,
|
||||||
ptr: 0,
|
ptr: 0,
|
||||||
reader: bufio.NewReader(os.Stdin),
|
reader: bufio.NewReader(in),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
m := gofuck.New()
|
m := gofuck.NewStdin()
|
||||||
instructions := make([]byte, 0)
|
instructions := make([]byte, 0)
|
||||||
|
|
||||||
// read in the instructions
|
// read in the instructions
|
||||||
|
|
Loading…
Reference in New Issue