package monkey import ( "io" "monkey/internal/context" "monkey/internal/vm" "os" ) // Options represents the options for running a script with Monkey. type Options struct { Debug bool // Whether to enable debug mode or not Trace bool // Whether to enable trace mode or not 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), context.WithStdout(opts.Stdout), context.WithStderr(opts.Stderr), context.WithExit(opts.Exit), ) return []vm.Option{ vm.WithDebug(opts.Debug), vm.WithTrace(opts.Trace), vm.WithContext(ctx), } }