core

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package core provides internal utilities for the TypeGo bridge layer.

This package contains low-level primitives used by the bridge to convert data between Go and JavaScript. It is not intended for direct use by TypeGo applications.

Index

Constants

This section is empty.

Variables

View Source
var GlobalTypes []byte

Functions

func BindStruct

func BindStruct(vm *sobek.Runtime, name string, s interface{}) error

BindStruct exposes a Go struct to JavaScript with full field and method access. Supports nested structs (converted recursively) and callback arguments.

func InitAll

func InitAll(vm *sobek.Runtime, el *eventloop.EventLoop)

Called once during engine startup.

func MapSharedBuffer

func MapSharedBuffer(vm *sobek.Runtime, name string, data []byte)

MapSharedBuffer exposes a Go byte slice as a global JavaScript TypedArray. The backing memory is shared between Go and JavaScript, meaning modifications from either side are immediately visible to the other.

The buffer is registered as a global variable with the given name, accessible as a Uint8Array in JavaScript. This is commonly used for inter-worker communication and zero-copy data sharing.

Example:

data := make([]byte, 1024)
core.MapSharedBuffer(vm, "sharedBuffer", data)
// In JS: sharedBuffer[0] = 42
// In Go: data[0] == 42

func RegisterConsole

func RegisterConsole(vm *sobek.Runtime)

func RegisterGlobals

func RegisterGlobals(vm *sobek.Runtime)

func RegisterModule

func RegisterModule(m Module)

Modules typically call this in their init() function.

func ToArrayBuffer

func ToArrayBuffer(vm *sobek.Runtime, data []byte) sobek.Value

ToArrayBuffer converts a Go byte slice to a JavaScript ArrayBuffer. The returned ArrayBuffer is a copy of the original data, so modifications in JavaScript will not affect the Go slice.

For shared memory scenarios where modifications should be visible to both Go and JavaScript, use MapSharedBuffer instead.

Types

type Binding

type Binding struct {
	Name   string
	Target interface{}
}

Binding represents a Go struct that has been bound to the JavaScript runtime.

type Console

type Console struct{}

func (*Console) Error

func (c *Console) Error(call sobek.FunctionCall) sobek.Value

func (*Console) Log

func (c *Console) Log(call sobek.FunctionCall) sobek.Value

type Module

type Module interface {
	// Name returns the module's import path (e.g., "go:fmt", "typego:memory")
	Name() string
	Register(vm *sobek.Runtime, el *eventloop.EventLoop)
}

func GetModules

func GetModules() []Module

Jump to

Keyboard shortcuts

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