AssemblyScript / assemblyscript

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

About encode(utf16/ucs2->utf8) #192

Closed iwojima closed 5 years ago

iwojima commented 6 years ago

Dear team,

Thank you for your contribution, we are developing a wasm virtual machine. and we need support Javascript , to write a JS code to convert to wast , so we find your project.

but we found the encode of string look like "utf16/ucs2" in compiled wasm file . It's difficult to recognize them in our virtual machine. for example , we defined a string as below:

var str = "123";

after compiling , it will be:

(data (i32.const 8) "\03\00\00\001\002\003")

we had tried to convert the string to utf8 , but convert function we defined can be passed by the compiler . can you give us any advice to fix the issue? or have you any way to convert string from "utf16/ucs2" to "utf8" ?

Thanks!

MaxGraey commented 6 years ago

Hi @iwojima, Thanks for your interest. AssemblyScript's String class provide two additional (non-standard for web API) methods for managing zero-terminated UTF8 strings which using for EOS contracts which run on WAVM VM.

String#lengthUTF8 String#toUTF8

Hope this help

yuanjunliang commented 6 years ago

How can I import String Class and use it. Import file 'assembly/assemblyscript.ts' not found when I import assemblyscript and build it

MaxGraey commented 6 years ago

You don't need explicit importing objects from std like String, Array, typed arrays, Map, Set, Symbol and etc.

dcodeIO commented 5 years ago

Closing this issue for now as it hasn't received any replies recently. Feel free to reopen it if necessary!