AssemblyScript / assemblyscript

A TypeScript-like language for WebAssembly.
https://www.assemblyscript.org
Apache License 2.0
16.6k stars 650 forks source link

How to convert the string returned by the function on other platforms (iso & Android) #2842

Closed 996ccs closed 2 months ago

996ccs commented 2 months ago

Question

I am currently using the latest version of assemblyscript (0.27.27). I wrote a function to return the "hello world" string. In the browser, WebAssembly exported a memory module for conversion, but on the iOS platform, I used WasmKit, a third-party wasm runtime. Load the wasm file to parse wasm. The parsed instance object memory is an empty array buffer. How can I get the "hello world" string returned by the function on ios and Android platforms?

Below is my code


function myAbort(message: usize, fileName: usize, line: u32, column: u32): void {

}

export function getHelloWorld(): string {
  return "hello world";
}

compile command

asc assembly/index.ts --target release --bindings esm --disable --use abort=assembly/index/myAbort

wat file


(module
 (type $0 (func (result i32)))
 (memory $0 1)
 (data $0 (i32.const 1036) ",")
 (data $0.1 (i32.const 1048) "\02\00\00\00\16\00\00\00h\00e\00l\00l\00o\00 \00w\00o\00r\00l\00d")
 (export "getHelloWorld" (func $assembly/index/getHelloWorld))
 (export "memory" (memory $0))
 (func $assembly/index/getHelloWorld (result i32)
  i32.const 1056
 )
)

The result I expect is that calling the getHelloWorld function on iOS and Android using a third-party wasm runtime library can return the "helloWorld" string, but now calling the getHelloWorld function returns a number type number.

CountBleck commented 2 months ago

The returned value is a pointer to a WTF-16 string in the exported memory. The memory should be 65536 bytes long and should most definitely not be empty.

996ccs commented 2 months ago

The returned value is a pointer to a WTF-16 string in the exported memory. The memory should be 65536 bytes long and should most definitely not be empty.

Thanks for your reply. On the browser platform memory is indeed 65536 bytes long data. The problem I encountered is that when using the third-party wasm runtime library on the ios platform, the wasmkit memory is an empty buffer array.

CountBleck commented 2 months ago

I'm afraid I don't know anything about this runtime, so I can't help in that regard.

996ccs commented 2 months ago

I'm afraid I don't know anything about this runtime, so I can't help in that regard.

Okay, thank you again for your reply. I will close this issue.