mirror of
https://gitee.com/wa-lang/wa.git
synced 2025-12-06 17:19:15 +08:00
简化 init 工程模板和 run 命令实现
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// 执行凹代码
|
||||
func RunCode(cfg *config.Config, filename, code string, args ...string) (stdoutStderr []byte, err error) {
|
||||
func RunCode(cfg *config.Config, filename, code string, mainFunc string, args ...string) (stdoutStderr []byte, err error) {
|
||||
// 编译为 wat 格式
|
||||
watBytes, err := BuildFile(cfg, filename, code)
|
||||
if err != nil {
|
||||
@@ -26,7 +26,7 @@ func RunCode(cfg *config.Config, filename, code string, args ...string) (stdoutS
|
||||
}
|
||||
|
||||
// main 执行
|
||||
stdout, stderr, err := wazero.RunWasm(cfg, filename, wasmBytes, args...)
|
||||
stdout, stderr, err := wazero.RunWasm(cfg, filename, wasmBytes, mainFunc, args...)
|
||||
stdoutStderr = append(stdout, stderr...)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func ExampleRunCode() {
|
||||
}
|
||||
`
|
||||
|
||||
output, err := api.RunCode(api.DefaultConfig(), "hello.wa", code)
|
||||
output, err := api.RunCode(api.DefaultConfig(), "hello.wa", code, "__main__.main")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func ExampleRunCode_args() {
|
||||
cfg.WaOS = api.WaOS_wasi
|
||||
|
||||
args := []string{"aa", "bb"}
|
||||
output, err := api.RunCode(cfg, "hello.wa", code, args...)
|
||||
output, err := api.RunCode(cfg, "hello.wa", code, "__main__.main", args...)
|
||||
if err != nil {
|
||||
if len(output) != 0 {
|
||||
log.Println(string(output))
|
||||
@@ -74,7 +74,7 @@ func ExampleRunCode_wz() {
|
||||
。
|
||||
`
|
||||
|
||||
output, err := api.RunCode(api.DefaultConfig(), "hello.wa", code)
|
||||
output, err := api.RunCode(api.DefaultConfig(), "hello.wa", code, "__main__.main")
|
||||
if err != nil {
|
||||
if len(output) != 0 {
|
||||
log.Println(string(output))
|
||||
|
||||
Reference in New Issue
Block a user