Documentation
¶
Overview ¶
Package std provides Buzz's standard library modules as native modules for the magus/buzz interpreter.
Call Register once after creating a session to make all modules available for import:
import "std" // assert, print, parseInt, toInt, char, random, panic, … import "math" // sin, cos, sqrt, pi, abs, … import "fs" // currentDirectory, makeDirectory, delete, move, list, exists import "os" // sleep, time, env, tmpDir, tmpFilename, exit, execute, Socket, TcpServer import "crypto" // HashAlgorithm enum + hash() import "gc" // allocated, collect import "debug" // dump, ast import "io" // File, FileMode, stdin, stdout, stderr, runFile import "serialize" // Boxed, serialize, jsonEncode, jsonDecode import "buffer" // Buffer
ffi is C-ABI native (see ffi.go): zdef() binds C functions, and the ffi module offers cstr, sizeOf/alignOf, sizeOfStruct/alignOfStruct, structLayout, and a pinned alloc/free/read/write memory API for out-parameters and by-reference structs. Type arguments are C type-name strings, not Zig types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Modules = []buzz.Module{ {Name: "std", Labels: []string{buzz.LabelUpstream}, Bind: func(s *buzz.Session, env buzz.ModuleEnv) error { s.SetNativeModule("std", coreModule(env.Out)) return nil }}, {Name: "math", Labels: []string{buzz.LabelUpstream}, Bind: synthetic("math", mathModule)}, {Name: "fs", Labels: []string{buzz.LabelUpstream}, Bind: synthetic("fs", fsModule)}, {Name: "os", Labels: []string{buzz.LabelUpstream}, Bind: synthetic("os", osModule)}, {Name: "cryptocore", Labels: []string{buzz.LabelGopherbuzz}, Bind: synthetic("cryptocore", cryptoCoreModule)}, {Name: "crypto", Labels: []string{buzz.LabelUpstream}, Bind: func(s *buzz.Session, _ buzz.ModuleEnv) error { s.SetNativeModule("crypto", cryptoCoreModule()) s.SetModuleDecls("crypto", cryptoSource) return nil }}, {Name: "gc", Labels: []string{buzz.LabelUpstream}, Bind: synthetic("gc", gcModule)}, {Name: "debug", Labels: []string{buzz.LabelUpstream}, Bind: synthetic("debug", debugModule)}, {Name: "iocore", Labels: []string{buzz.LabelGopherbuzz}, Bind: func(s *buzz.Session, _ buzz.ModuleEnv) error { s.SetNativeModule("iocore", ioCoreModule(s)) return nil }}, {Name: "io", Labels: []string{buzz.LabelUpstream}, Bind: func(s *buzz.Session, _ buzz.ModuleEnv) error { s.SetNativeModule("io", ioCoreModule(s)) s.SetModuleDecls("io", ioSource) s.SetModuleDecls("os", osSource) return nil }}, {Name: "serialize", Labels: []string{buzz.LabelUpstream}, Bind: synthetic("serialize", serializeModule)}, {Name: "buffer", Labels: []string{buzz.LabelUpstream}, Bind: synthetic("buffer", bufferModule)}, {Name: "ffi", Labels: []string{buzz.LabelUpstream}, Bind: synthetic("ffi", ffiModule)}, {Name: "assertcore", Labels: []string{buzz.LabelGopherbuzz}, Bind: synthetic("assertcore", assertCoreModule)}, {Name: "assert", Labels: []string{buzz.LabelGopherbuzz}, Bind: source("assert", assertSource)}, {Name: "suite", Labels: []string{buzz.LabelGopherbuzz}, Bind: source("suite", suiteSource)}, {Name: "testing", Labels: []string{buzz.LabelGopherbuzz}, Bind: source("testing", testingSource)}, {Name: "test", Labels: []string{buzz.LabelUpstream}, Bind: source("test", testingSource)}, }
Modules is the single source of truth for the modules gopherbuzz bundles: the upstream-faithful stdlib (buzz.LabelUpstream) plus gopherbuzz's own test surface (buzz.LabelGopherbuzz). Register provides every entry; a caller filters by label for a subset. Edit this table to add a module. The registration shape is buzz.Module (see gopherbuzz/module.go), shared with host embedders.
Functions ¶
func CwdFromContext ¶
CwdFromContext returns the working directory set by WithCwd and whether one is set. It is the reader counterpart to WithCwd, so an embedder that layers its own cwd on top (e.g. magus) can confirm the value propagated into this stdlib.
func Register ¶
Register installs every bundled module on sess. std.print writes to os.Stdout; use RegisterWithOutput to redirect it.
func RegisterWithOutput ¶
RegisterWithOutput is Register with std.print directed to out. An embedding that captures a program's textual output (e.g. the WebAssembly playground) passes its own writer so print lands in a buffer instead of the host stdout.
func SkipMessage ¶
SkipMessage reports whether err is a test-skip signal (from assert\skip) and, if so, returns the skip reason. Test runners call it to classify a test-block error as skipped rather than failed.
func WithCwd ¶
WithCwd returns ctx carrying dir as the working directory the std builtins (fs.*, io.File/io.runFile, os.execute) resolve relative paths against. An empty dir is a no-op. Exported so an embedder can establish it; the stdlib reads it internally via resolve. Absolute paths and scripts run without a cwd are unaffected, so this extends the standard library's behavior rather than changing it.
Types ¶
This section is empty.