# runtime

> Runtime introspection and a process-global shared key-value store, plus reflect, error, panic, and env helpers.

# 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.

| Function | Signature | Description |
| --- | --- | --- |
| `share` | `runtime.core.share(key: string, value: string) → void` | Store a value under a key |
| `fetch` | `runtime.core.fetch(key: string) → string` | Read a key (empty string if absent) |
| `remove` | `runtime.core.remove(key: string) → void` | Delete a key |
| `keys` | `runtime.core.keys() → string[]` | All stored keys |
| `has` | `runtime.core.has(key: string) → bool` | Whether a key exists |

## runtime.reflect

| Function | Signature | Description |
| --- | --- | --- |
| `typeOf` | `runtime.reflect.typeOf(v: any) → string` | The value's type name |
| `isInt` | `runtime.reflect.isInt(v: any) → bool` | Whether `v` is an int |
| `isFloat` | `runtime.reflect.isFloat(v: any) → bool` | Whether `v` is a float |
| `isString` | `runtime.reflect.isString(v: any) → bool` | Whether `v` is a string |
| `isBool` | `runtime.reflect.isBool(v: any) → bool` | Whether `v` is a bool |
| `isArray` | `runtime.reflect.isArray(v: any) → bool` | Whether `v` is an array |
| `isFunction` | `runtime.reflect.isFunction(v: any) → bool` | Whether `v` is a function or builtin |
| `isModule` | `runtime.reflect.isModule(v: any) → bool` | Whether `v` is a module |
| `isVoid` | `runtime.reflect.isVoid(v: any) → bool` | Whether `v` is void |

## runtime.info

| Function | Signature | Description |
| --- | --- | --- |
| `version` | `runtime.info.version() → string` | Go runtime version |
| `numCPU` | `runtime.info.numCPU() → int` | Number of logical CPUs |
| `goroutines` | `runtime.info.goroutines() → int` | Current goroutine count |
| `goarch` | `runtime.info.goarch() → string` | Target architecture |
| `goos` | `runtime.info.goos() → string` | Target OS |

## runtime.error

| Function | Signature | Description |
| --- | --- | --- |
| `new` | `runtime.error.new(msg: any) → string` | Create an error-tagged string |
| `message` | `runtime.error.message(errStr: string) → string` | Extract the message from an error string |
| `isError` | `runtime.error.isError(v: any) → bool` | Whether the value is an error string |

## runtime.panic

| Function | Signature | Description |
| --- | --- | --- |
| `throw` | `runtime.panic.throw(msg?: any) → void` | Print `[PANIC] <msg>` to stderr and exit with code 2 |

## runtime.env

| Function | Signature | Description |
| --- | --- | --- |
| `get` | `runtime.env.get(key: string) → string` | Read an environment variable (empty string if unset) |
| `set` | `runtime.env.set(key: string, val: string) → bool` | Set an environment variable |
| `args` | `runtime.env.args() → string[]` | Process command-line arguments |

## Example

```goost
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
}
```