1.0.3 • Published 11 months ago

@tectonica/vm v1.0.3

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

@tectonica/vm

Install

pnpm install @tectonica/vm

Usage

import { VMManager } from '@tectonica/vm'
// create a new manager
const vm = new VMManager()
// initialize the runtime/contexts
await vm.init()

// eval simple code
const result = vm.eval(`6 + 4`) // returns 10

// eval with context
const scopedResult = vm.scopedEval(`num1 + num2`, { num1: 3, num2: 2 }) // returns 5

// register globals
vm.registerVMGlobal('global1', {
  test: () => {
    console.log('hello!')
    return 12
  },
})
// access globals in future evals
const globalresult = vm.eval(`global1()`) // logs `hello` and returns 12

Bundlers

If your project is bundled with something like Vite, you may need to specify the wasmLocation for where the file ends up after bundling

import { VMManager } from '@tectonica/vm'
import wasmLocation from '@jitl/quickjs-wasmfile-release-sync/wasm?url'

const vm = new VMManager()
await vm.init({
  variantOptions: {
    wasmLocation,
  },
})
1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago