fmt

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package fmt exposes some functionality of the Go stdlib fmt package to a quickjs.VM.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(obj quickjs.Value) (err error)

Register sets the "fmt" property of 'obj' to the fmt package javascript object.

The functions registered are

The javascript functions follow the usual conventions where the first letter of a function name is not capitalized. So fmt.Println becomes 'fmt.println' in javascript, for example.

Example (Printf)
m, _ := quickjs.NewVM()
defer m.Close()
g := m.GlobalObject()
defer g.Free()
Register(g.Dup())
v, _ := m.Eval("fmt.printf('Math.PI=%v\\n', Math.PI)", quickjs.EvalGlobal)
fmt.Print(v)
Output:
Math.PI=3.141592653589793
[26,null]
Example (Sprint)
m, _ := quickjs.NewVM()
defer m.Close()
g := m.GlobalObject()
defer g.Free()
Register(g.Dup())
v, _ := m.Eval("fmt.sprint([2*21, 'foo', {bar: Math.exp(1)}])", quickjs.EvalGlobal)
fmt.Print(v)
Output:
[42,"foo",{"bar":2.718281828459045}]

Types

This section is empty.

Jump to

Keyboard shortcuts

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