assemblyscript

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 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 assemblyscript contains Go-defined special functions imported by AssemblyScript under the module name "env".

Special Functions

AssemblyScript code import the below special functions when not using WASI. Note: Sometimes only "abort" is imported.

  • "abort" - exits with 255 with an abort message written to wazy.ModuleConfig WithStderr.
  • "trace" - no output unless.
  • "seed" - uses wazy.ModuleConfig WithRandSource as the source of seed values.

See https://www.assemblyscript.org/concepts.html#special-imports

Relationship to WASI

AssemblyScript supports compiling JavaScript functions that use I/O, such as `console.log("hello")`. However, WASI is not built-in to AssemblyScript. Use the `wasi-shim` to compile if you get import errors.

See https://github.com/AssemblyScript/wasi-shim#usage and wasi_snapshot_preview1.Instantiate for more.

Example (FunctionExporter)

This shows how to instantiate AssemblyScript's special imports when you also need other functions in the "env" module.

package main

import (
	"context"

	_ "embed"
	"github.com/samyfodil/wazy"
	"github.com/samyfodil/wazy/api"
	"github.com/samyfodil/wazy/imports/assemblyscript"
)

func main() {
	ctx := context.Background()

	r := wazy.NewRuntime(ctx)
	defer r.Close(ctx) // This closes everything this Runtime created.

	// First construct your own module builder for "env"
	envBuilder := r.NewHostModuleBuilder("env").
		NewFunctionBuilder().
		WithGoFunction(api.GoFunc(func(_ context.Context, stack []uint64) {
			stack[0] = api.EncodeU32(1)
		}), nil, []api.ValueType{api.ValueTypeI32}).
		Export("get_int")

	// Now, add AssemblyScript special function imports into it.
	assemblyscript.NewFunctionExporter().
		WithAbortMessageDisabled().
		ExportFunctions(envBuilder)

}
Example (Instantiate)

This shows how to instantiate AssemblyScript's special imports.

package main

import (
	"context"

	_ "embed"
	"github.com/samyfodil/wazy"
	"github.com/samyfodil/wazy/imports/assemblyscript"
)

func main() {
	ctx := context.Background()

	r := wazy.NewRuntime(ctx)
	defer r.Close(ctx) // This closes everything this Runtime created.

	// This adds the "env" module to the runtime, with AssemblyScript's special
	// function imports.
	assemblyscript.MustInstantiate(ctx, r)

}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Instantiate

func Instantiate(ctx context.Context, r wazy.Runtime) (api.Closer, error)

Instantiate instantiates the "env" module used by AssemblyScript into the runtime.

Notes

  • Failure cases are documented on wazy.Runtime InstantiateModule.
  • Closing the wazy.Runtime has the same effect as closing the result.
  • To add more functions to the "env" module, use FunctionExporter.

func MustInstantiate

func MustInstantiate(ctx context.Context, r wazy.Runtime)

MustInstantiate calls Instantiate or panics on error.

This is a simpler function for those who know the module "env" is not already instantiated, and don't need to unload it.

Types

type FunctionExporter

type FunctionExporter interface {
	// WithAbortMessageDisabled configures the AssemblyScript abort function to
	// discard any message.
	WithAbortMessageDisabled() FunctionExporter

	// WithTraceToStdout configures the AssemblyScript trace function to output
	// messages to Stdout, as configured by wazy.ModuleConfig WithStdout.
	WithTraceToStdout() FunctionExporter

	// WithTraceToStderr configures the AssemblyScript trace function to output
	// messages to Stderr, as configured by wazy.ModuleConfig WithStderr.
	//
	// Because of the potential volume of trace messages, it is often more
	// appropriate to use WithTraceToStdout instead.
	WithTraceToStderr() FunctionExporter

	// ExportFunctions builds functions to export with a wazy.HostModuleBuilder
	// named "env".
	ExportFunctions(wazy.HostModuleBuilder)
}

FunctionExporter configures the functions in the "env" module used by AssemblyScript.

Notes

  • This is an interface for decoupling, not third-party implementations. All implementations are in wazy.

func NewFunctionExporter

func NewFunctionExporter() FunctionExporter

NewFunctionExporter returns a FunctionExporter object with trace disabled.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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