Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
99 lines (65 loc) · 1.88 KB

File metadata and controls

99 lines (65 loc) · 1.88 KB
Copy raw file
Download raw file
Outline
Edit and raw actions
title WebASM VM
sidebar_position 100

Web Assembly Virtual Machine

The @devicescript/vm package contains DeviceScript C virtual machine compiled to Web Assembly. It allows you to run bytecode in node.js and browsers

This package is used in the CLI and in developer tools web page.

npm install --save @devicescript/vm

import

Loading the virtual machine is async and should typically be cached in a global variable.

Node.js

import type { DevsModule } from "@devicescript/vm"

const vmLoader = require("@devicescript/vm")
const vm: DevsModule = await vmLoader()
vm.devsInit()

Browser

import type { DevsModule } from "@devicescript/vm"
import vmLoader from "@devicescript/vm"

const vm: DevsModule = await vmLoader()
vm.devsInit()

or import https://microsoft.github.io/devicescript/dist/devicescript-vm.js for the latest build.

devsSetDeviceId

Specifies the device id of the virtual machine device. This method should be called before starting the virtual machine.

vm.devsSetDeviceId("1989f4eee0ebe206")

devsStart

Starts the virtual machine. Does nothing if already running.

const res = vm.devsStart()
if (res) console.error("failed to start", res)

devsStop

Stops the virtual machine. Does nothing if already stopped.

vm.devsStop()

devsIsRunning

Indicates if the virtual machine is started.

const running = vm.devsIsRunning()

devsInit

This method allocates data structures necessary for running the virtual machine. It is automatically called by other metods.

vm.devsInit()

devsVerify

Verifies that a buffer of bytecode is well formed. Returns non-zero error codes when failing.

const res = vm.devsVerify()
if (res) console.error("failed to verify", res)

devsClearFlash

Clear persistent "flash" storage.

vm.devsClearFlash()
Morty Proxy This is a proxified and sanitized view of the page, visit original site.