optimizations
This commit is contained in:
33
options.go
33
options.go
@@ -1,23 +1,38 @@
|
||||
package monkey
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"monkey/internal/context"
|
||||
"monkey/internal/vm"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Options represents the options for running a script with Monkey.
|
||||
type Options struct {
|
||||
Debug bool
|
||||
Trace bool
|
||||
Debug bool // Whether to enable debug mode or not
|
||||
Trace bool // Whether to enable trace mode or not
|
||||
|
||||
Args []string
|
||||
Stdin io.Reader
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
Exit func(int)
|
||||
Args []string // The arguments passed to the script
|
||||
Stdin io.Reader // The input reader for the script
|
||||
Stdout io.Writer // The output writer for the script
|
||||
Stderr io.Writer // The error writer for the script
|
||||
Exit func(int) // A function to call when the script exits
|
||||
}
|
||||
|
||||
func (opts Options) ToVMOptions() []vm.Option {
|
||||
if opts.Stdin == nil {
|
||||
opts.Stdin = os.Stdin
|
||||
}
|
||||
if opts.Stdout == nil {
|
||||
opts.Stdout = os.Stdout
|
||||
}
|
||||
if opts.Stderr == nil {
|
||||
opts.Stderr = os.Stderr
|
||||
}
|
||||
if opts.Exit == nil {
|
||||
opts.Exit = os.Exit
|
||||
}
|
||||
|
||||
ctx := context.New(
|
||||
context.WithArgs(opts.Args),
|
||||
context.WithStdin(opts.Stdin),
|
||||
@@ -28,7 +43,7 @@ func (opts Options) ToVMOptions() []vm.Option {
|
||||
|
||||
return []vm.Option{
|
||||
vm.WithDebug(opts.Debug),
|
||||
vm.WithDebug(opts.Trace),
|
||||
vm.WithTrace(opts.Trace),
|
||||
vm.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user