Escribe para buscar…

Assembly Script

A TypeScript-like language for WebAssembly

Esta página todavía no se ha traducido — se muestra en su idioma original:English

Introduction

AssemblyScript compiles a variant of TypeScript (a typed superset of JavaScript) to WebAssembly using Binaryen.

Good use cases for AssemblyScript are computation-heavy logic like image manipulation, hot game logic, specialized algorithms, emulators, compilers, and the likes.

Project

Create a new project with Deno

ps
deno init assembly
ps
npm init -y
npm install --save-dev assemblyscript
npx asinit .

This creates assembly/ with index.ts and asconfig.json, plus build scripts in package.json.

Build the WebAssembly module

ps
npm run asbuild      # or: npx asc assembly/index.ts --target release

Output will be in build/ (e.g., build/release.wasm).

Import and run the WASM in Deno

Create main.ts:

ts
const wasmUrl = new URL("./build/release.wasm", import.meta.url);
const wasmModule = await WebAssembly.instantiate(
  await Deno.readFile(wasmUrl),
  {}, // import object if needed
);
const { add } = wasmModule.instance.exports as { add(a: number, b: number): number };
console.log(add(2, 3)); // expect 5

Estás leyendo una vista previa.

Inicia sesión para leer el artículo completo. Cualquier cuenta abre 4 artículos gratuitos al mes; el alumnado y el profesorado leen las páginas de su curso sin límite.

Iniciar sesión