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 ¶
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.
Click to show internal directories.
Click to hide internal directories.