wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go
https://pkg.go.dev/github.com/wasmerio/wasmer-go
MIT License
2.84k stars 161 forks source link

Go compiles to webassembly,wasmer-go to call,Implement memory read and write #349

Open mougeCM opened 2 years ago

mougeCM commented 2 years ago

I found: https://github.com/wasmerio/wasmer-go/blob/master/examples/example_memory_test.go

Can you give a go code instead of wat?

(module
          (type $mem_size_t (func (result i32)))
          (type $get_at_t (func (param i32) (result i32)))
          (type $set_at_t (func (param i32) (param i32)))
          (memory $mem 1)
          (func $get_at (type $get_at_t) (param $idx i32) (result i32)
            (i32.load (local.get $idx)))
          (func $set_at (type $set_at_t) (param $idx i32) (param $val i32)
            (i32.store (local.get $idx) (local.get $val)))
          (func $mem_size (type $mem_size_t) (result i32)
            (memory.size))
          (export "get_at" (func $get_at))
          (export "set_at" (func $set_at))
          (export "mem_size" (func $mem_size))
          (export "memory" (memory $mem)))
mougeCM commented 2 years ago

The ideal situation is to encapsulate linear memory reading and provide Write and Read methods

Similar to wazero demo: https://github.com/tetratelabs/wazero/blob/main/examples/allocation/tinygo/greet.go

HBrightShown commented 1 year ago

in wasmer-go i cannot find this example, so i don't known how to transfer struct and string to wasm file, the wazero have this example ?