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 ¶
- Variables
- func BindStruct(vm *goja.Runtime, name string, s interface{}) error
- func InitAll(vm *goja.Runtime, el *eventloop.EventLoop)
- func MapSharedBuffer(vm *goja.Runtime, name string, data []byte)
- func RegisterConsole(vm *goja.Runtime)
- func RegisterGlobals(vm *goja.Runtime)
- func RegisterModule(m Module)
- func ToArrayBuffer(vm *goja.Runtime, data []byte) goja.Value
- type Binding
- type Console
- type Module
Constants ¶
This section is empty.
Variables ¶
var GlobalTypes []byte
Functions ¶
func BindStruct ¶
BindStruct exposes a Go struct to JavaScript with full field and method access. Supports nested structs (converted recursively) and callback arguments.
func MapSharedBuffer ¶
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 ¶
RegisterConsole injects the console object into the runtime
func RegisterGlobals ¶
RegisterGlobals injects global helper functions into the runtime
func RegisterModule ¶
func RegisterModule(m Module)
RegisterModule adds a module to the global registry. Modules typically call this in their init() function.
func ToArrayBuffer ¶
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{}
Console implements the JS console object
type Module ¶
type Module interface {
// Name returns the module's import path (e.g., "go:fmt", "typego:memory")
Name() string
// Register injects the module's bindings into the JavaScript runtime
Register(vm *goja.Runtime, el *eventloop.EventLoop)
}
Module represents a registerable TypeGo module.
func GetModules ¶
func GetModules() []Module
GetModules returns all registered modules (for debugging/introspection).