How to use the assemblyscript/lib/loader.instantiateBuffer function in assemblyscript

To help you get started, we’ve selected a few assemblyscript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AssemblyScript / node / tests / node.js View on Github external
function runTest(file, type, binary, wat) {
  const context = new TestContext({
    fileName: file,
    reporter,
    stderr: process.stderr,
    stdout: process.stdout,
  });
  const imports = context.createImports({
    wasi_unstable: wasi.exports,
  });
  const wasm = instantiateBuffer(binary, imports);
  wasi.setMemory(wasm.memory);
  wasi.view = new DataView(wasm.memory.buffer);
  context.run(wasm);
}
github kyranet / levenshtein-wasm / index.js View on Github external
const { readFileSync } = require('fs');
const { instantiateBuffer } = require('assemblyscript/lib/loader');

const wasmModule = instantiateBuffer(readFileSync(`${__dirname}/build/optimized.wasm`));

module.exports = function levenshtein(a, b) {
  if (a === b) return 0;
  if (a.length > b.length) [a, b] = [b, a];
  return wasmModule.levenshtein(wasmModule.newString(a), wasmModule.newString(b));
};