wasmer-go icon indicating copy to clipboard operation
wasmer-go copied to clipboard

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

Open mougeCM opened this issue 2 years ago • 2 comments

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 avatar Aug 27 '22 10:08 mougeCM

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

mougeCM avatar Aug 27 '22 10:08 mougeCM

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 ?

HBrightShown avatar Apr 13 '23 02:04 HBrightShown