rt

package
v0.0.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package rt provides a JavaScript runtime for hydris plugins using goja.

Index

Constants

This section is empty.

Variables

View Source
var ConnectBLEFunc = func(address string) (hal.BLEConnection, error) {
	return hal.ConnectBLE(address)
}

ConnectBLEFunc establishes a BLE GATT connection via the HAL.

View Source
var OpenSerialFunc = func(path string, baudRate int) (io.ReadWriteCloser, error) {
	return hal.OpenSerial(path, baudRate)
}

OpenSerialFunc opens a serial port via the HAL.

Functions

func FindDataDir

func FindDataDir(path string) string

FindDataDir walks up from path to find the directory containing package.json. Returns empty string if not found.

func RunPlugin

func RunPlugin(ctx context.Context, bundlePath string, dataDir string) error

RunPlugin runs a JS bundle in goja with automatic restart on crash. Blocks until ctx is cancelled. Suitable for both CLI and in-process (android) use. dataDir is the plugin source directory (containing package.json) used to sandbox file access; pass "" to disable.

func RunPluginEnv

func RunPluginEnv(ctx context.Context, bundlePath, dataDir, serverURL string) error

RunPluginEnv is like RunPlugin but sets HYDRIS_SERVER first.

Types

type Option added in v0.0.21

type Option func(*Runtime)

Option configures a Runtime.

func WithLogWriter added in v0.0.21

func WithLogWriter(w io.Writer) Option

WithLogWriter directs console.log/warn/error output to w.

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime wraps a goja event loop with the globals needed by hydris plugins.

func New

func New(dataDir string, opts ...Option) *Runtime

New creates a Runtime. dataDir is the plugin's source directory (containing package.json) used to sandbox file access. The event loop provides setTimeout/setInterval, console, and CommonJS require out of the box via goja_nodejs. Node.js-compatible http2, events, stream modules are registered so that connect-rpc bundles work without modification.

func (*Runtime) RunFile

func (r *Runtime) RunFile(ctx context.Context, path string) error

RunFile reads path and executes it. Blocks until ctx is cancelled.

func (*Runtime) RunScript

func (r *Runtime) RunScript(ctx context.Context, name, src string) error

RunScript executes src inside the event loop. Uses Start() so the loop stays alive for async operations (fetch, promises). Blocks until ctx is cancelled.

func (*Runtime) Stop

func (r *Runtime) Stop()

Stop terminates the event loop.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL