Skip to content

scorsi/webassembly-stdweb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webassembly-stdweb

A library for binding standard javascript function to WebAssembly language such as AssemblyScript

Actual bindings

namespace status
console partially
websocket partially
document not started yet

How to make bindings

const fs = require('fs'); const loader = require('../src/loader'); let wasmModule = undefined; // IMPORTANT const getModule = () => wasmModule; // IMPORTANT let imports = {}; imports["_console"] = require('.../bindings/console')(getModule); imports["_websocket"] = require('.../bindings/websocket')(getModule); wasmModule = loader.instantiateBuffer(fs.readFileSync('./build/optimized.wasm'), imports); // DO SOMETHING

How to use Declarations in AssemblyScript

Console

import {Console} from ".../declarations/console"; Console.log("Hello World !"); Console.log(42); Console.log(0.0);

WebSocket

import {WebSocket} from ".../declarations/websocket"; let ws = new WebSocket("ws://localhost:8080"); export function onClose(): void { // DO SOMETHING } export function onError(): void { // DO SOMETHING } export function onMessage(message: string): void { // DO SOMETHING } export function onOpen(): void { // DO SOMETHING } ws.registerCallbackOnOpen(onOpen); ws.registerCallbackOnClose(onClose); ws.registerCallbackOnError(onError); ws.registerCallbackOnMessage(onMessage); ws.sendMessage("Hello World !")

About

A library for binding standard javascript functions to AssemblyScript

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published