optimizations
Some checks failed
Build / build (push) Successful in 10m29s
Publish Image / publish (push) Failing after 31s
Test / build (push) Failing after 6m34s

This commit is contained in:
Chuck Smith
2024-04-02 14:08:08 -04:00
parent 4c9ec5aaaa
commit 07fd82b261
23 changed files with 296 additions and 265 deletions

View File

@@ -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),
}
}