| title | WebASM VM |
|---|---|
| sidebar_position | 100 |
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/vmLoading the virtual machine is async and should typically be cached in a global variable.
import type { DevsModule } from "@devicescript/vm"
const vmLoader = require("@devicescript/vm")
const vm: DevsModule = await vmLoader()
vm.devsInit()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.
Specifies the device id of the virtual machine device. This method should be called before starting the virtual machine.
vm.devsSetDeviceId("1989f4eee0ebe206")Starts the virtual machine. Does nothing if already running.
const res = vm.devsStart()
if (res) console.error("failed to start", res)Stops the virtual machine. Does nothing if already stopped.
vm.devsStop()Indicates if the virtual machine is started.
const running = vm.devsIsRunning()This method allocates data structures necessary for running the virtual machine. It is automatically called by other metods.
vm.devsInit()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)Clear persistent "flash" storage.
vm.devsClearFlash()