runtime

Inspect the running program, share state across VMs through a process-global store, reflect on value types, and work with errors, panics, and environment variables. Import it with import runtime.

runtime.core

A string key-value store shared across all VMs in the process.

FunctionSignatureDescription
shareruntime.core.share(key: string, value: string) → voidStore a value under a key
fetchruntime.core.fetch(key: string) → stringRead a key (empty string if absent)
removeruntime.core.remove(key: string) → voidDelete a key
keysruntime.core.keys() → string[]All stored keys
hasruntime.core.has(key: string) → boolWhether a key exists

runtime.reflect

FunctionSignatureDescription
typeOfruntime.reflect.typeOf(v: any) → stringThe value’s type name
isIntruntime.reflect.isInt(v: any) → boolWhether v is an int
isFloatruntime.reflect.isFloat(v: any) → boolWhether v is a float
isStringruntime.reflect.isString(v: any) → boolWhether v is a string
isBoolruntime.reflect.isBool(v: any) → boolWhether v is a bool
isArrayruntime.reflect.isArray(v: any) → boolWhether v is an array
isFunctionruntime.reflect.isFunction(v: any) → boolWhether v is a function or builtin
isModuleruntime.reflect.isModule(v: any) → boolWhether v is a module
isVoidruntime.reflect.isVoid(v: any) → boolWhether v is void

runtime.info

FunctionSignatureDescription
versionruntime.info.version() → stringGo runtime version
numCPUruntime.info.numCPU() → intNumber of logical CPUs
goroutinesruntime.info.goroutines() → intCurrent goroutine count
goarchruntime.info.goarch() → stringTarget architecture
goosruntime.info.goos() → stringTarget OS

runtime.error

FunctionSignatureDescription
newruntime.error.new(msg: any) → stringCreate an error-tagged string
messageruntime.error.message(errStr: string) → stringExtract the message from an error string
isErrorruntime.error.isError(v: any) → boolWhether the value is an error string

runtime.panic

FunctionSignatureDescription
throwruntime.panic.throw(msg?: any) → voidPrint [PANIC] <msg> to stderr and exit with code 2

runtime.env

FunctionSignatureDescription
getruntime.env.get(key: string) → stringRead an environment variable (empty string if unset)
setruntime.env.set(key: string, val: string) → boolSet an environment variable
argsruntime.env.args() → string[]Process command-line arguments

Example

import runtime

// share state across VMs
runtime.core.share("session", "abc123")
print(runtime.core.fetch("session"))   // abc123

// inspect the runtime
print(runtime.info.numCPU())
print(runtime.info.goos())

// type checks and errors
let v = 42
if runtime.reflect.isInt(v) {
  print("int: " + runtime.reflect.typeOf(v))
}

let err = runtime.error.new("not found")
if runtime.error.isError(err) {
  print(runtime.error.message(err))    // not found
}
Standard library · View as Markdown · llms-full.txt