utf8 const string
Basic Usage
In WARPO, string will be encoded to utf16 to ensure the same behavior with TS. But it is also a common requirement to use string in FFI. In low level WebAssembly runtime, the native string most likely is utf8 encoded, for example rust or C++.
To use this feature, explicit import warpo:utf8_const_str from
ts
import * as utf8 from "warpo/utf8/const_str";
let s = utf8.build("abcdef");
assert(s.size == 6);
assert(s.toString() == "abcdef");upgrade guideline from assemblyscript-transform
Removing transform script in command line options
--transform ./node_modules/@schleifner/assemblyscript-transform/dist/transformBuildUtf8ConstStr.mjs.When you never go back to assemblyscript, following the example code to replace the import statements.
When you want to keep flexibility between assemblyscript and warpo, creating shim and adding
create.tsin project root.ts// lib/utf8-shim/as/utf8ConstStr.ts import * as utf8 from "warpo/utf8/const_str"; export { utf8 };ts// create.ts import * as resolveModule from "warpo/create/resolveModule"; import { __dirname } from "warpo/create"; resolveModule.onModuleResolve((task: resolveModule.ModuleResolve): void => { if (task.packageName === "@schleifner/assemblyscript-transform") { task.setPackagePath(__dirname + "/lib/utf8-shim"); } });