nativehost

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nativehost is how package native reaches what a phone's host gives it, through functions the host's Go side (internal/mobile) sets as it starts: the UI thread, where Swift's main actor and Android's views live, apart from Go's main thread there; and on Android the Kotlin implementations of native modules, which Go calls through JNI. Apps without native modules link only these variables.

Index

Constants

This section is empty.

Variables

View Source
var Handle func(kind, id uint64, status int64, data []byte) (int64, []byte, bool)

Handle answers what Kotlin tells Go through the callback modules share (package native's handle): kind, id, status and the encoded data, and returns the answer of a question, its status and data, and whether there is one. Package native sets it.

View Source
var OnUI func(fn func())

OnUI runs fn on the UI thread and waits for it, or runs it at once on the UI thread. Phones only; nil elsewhere, where Go's main thread is the system's.

View Source
var PostUI func(fn func())

PostUI runs fn on the UI thread later. Phones only.

Functions

This section is empty.

Types

type KotlinBridge

type KotlinBridge struct {
	// Init loads class, the module's generated object, under name, with
	// idBase in the high bits of the ids it makes. It returns an error's
	// message, or "".
	Init func(name, class string, idBase uint64) string
	// Invoke calls the function sym of the module on the object h, with
	// the encoded arguments args and the call's id (0 for one answered at
	// once). The answer is its status, then its encoded result; nil is
	// status 0 with nothing.
	Invoke func(name, sym string, h uint64, args []byte, call uint64) []byte
	// Direct calls the method of numbers sym, with args as their bits.
	Direct func(name, sym string, h uint64, args []uint64) uint64
	// Op runs one of release (a: the object), cancel and next (a: the
	// call), or resume (a: the continuation, with status and data).
	Op func(name, op string, a uint64, status int64, data []byte)
	// Malloc returns the address of n bytes of C memory, which Free frees.
	Malloc func(n int) uintptr
	Free   func(p uintptr)
}

KotlinBridge calls the Kotlin side of native modules.

var Kotlin *KotlinBridge

Kotlin is the JNI side of native modules implemented in Kotlin, on Android: what jni_android.c calls in dev.mygo.Native. Every function takes the module's name, which its Kotlin class registered under with Init.

Jump to

Keyboard shortcuts

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