diff options
| author | Mel <einebeere@gmail.com> | 2022-08-17 00:07:35 +0000 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-08-17 00:07:35 +0000 |
| commit | be6cd2217b6bb1bb411d46ebd9d003dfd928af96 (patch) | |
| tree | 94e5807aae0fb65d2768adce594e245052ecf578 /pkg/lang/vm/output.go | |
| parent | d84c0f36afcde4e5af2907d70931de75957d5277 (diff) | |
| download | jinx-be6cd2217b6bb1bb411d46ebd9d003dfd928af96.tar.zst jinx-be6cd2217b6bb1bb411d46ebd9d003dfd928af96.zip | |
Add different "say" outputs to VM
Diffstat (limited to 'pkg/lang/vm/output.go')
| -rw-r--r-- | pkg/lang/vm/output.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/pkg/lang/vm/output.go b/pkg/lang/vm/output.go new file mode 100644 index 0000000..1ef2357 --- /dev/null +++ b/pkg/lang/vm/output.go @@ -0,0 +1,45 @@ +package vm + +type Output interface { + Write(message string) error +} + +type EmptyOutput struct{} + +func NewEmptyOutput() *EmptyOutput { + return &EmptyOutput{} +} + +func (o *EmptyOutput) Write(message string) error { + return nil +} + +type GatheringOutput struct { + messages []string +} + +func NewGatheringOutput() *GatheringOutput { + return &GatheringOutput{ + messages: make([]string, 0, 8), + } +} + +func (o *GatheringOutput) Messages() []string { + return o.messages +} + +func (o *GatheringOutput) Write(message string) error { + o.messages = append(o.messages, message) + return nil +} + +type ConsoleOutput struct{} + +func NewConsoleOutput() *ConsoleOutput { + return &ConsoleOutput{} +} + +func (o *ConsoleOutput) Write(message string) error { + println(message) + return nil +} |
