bytecodealliance / bytecodealliance/wasmtime-go

Add SetStdout SetStdin

Open
#34 4 comments 8 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
913
Forks
100
Avg merge
10m
Merged PRs (30d)
1

Description

I saw that I cannot easily convert the string `path` in `SetStdoutFile(path string)` to the `io.ReadWriter` on wasmtime-go, so this is a suggestion to wasmtime.

`io.ReadWriter` is an interface which implemented by `os.File` and `bytes.Buffer`. With an `io.ReadWriter` as the parameter for WASI config, golang can operate its favor bytes without filesystem-level io, which means the WASI call will be more easy safe and stable.

```go
buf := bytes.NewBuffer(nil)
config := wasmtime.NewWasiConfig()
config.SetStdin(buf)
config.SetStdout(buf)

// then instaniate the wasi with the config

go func(){
b, err buf.ReadBytes('\n')
// handle this
}()
go instance.GetExport("_start").Func().Call()
// now intance request a stdin
buf.Write("continue exec")

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.