App and System
The app lifecycle (App), process and platform info (System), and autotest hooks.
Always available
No import needed. These names are in scope in every file.
App static class
ts
static class AppThe application lifecycle surface shared by console and windowed programs. App.onFrame is the canonical frame hook. Window projects additionally provide the resize and focus lifecycle callbacks.
App.onTick
ts
static onTick(handler: any): FunctionRegisters a fixed-tick handler, called once per logic tick (App.tps per second, catching up to maxCatchUpTicks ticks after a slow frame). Returns the function that unsubscribes it. A console program with a tick handler keeps running until App.quit().
App.ticker
ts
static readonly ticker: TickerThe app-lifetime Ticker (App.ticker.every(1, fn), await App.ticker.wait(2)), advanced once per scaled tick by the runtime, after App.onTick handlers. Created on first use. Reading it makes the program tick (a console program with ticker entries runs until App.quit()).
App.tps
ts
static tps: floatLogic ticks per second (default 60; also tps in thicket.json). Set to App.SYNC_WITH_FPS for one tick per drawn frame.
App.SYNC_WITH_FPS
ts
static readonly SYNC_WITH_FPS: floatApp.tps value that runs one tick per drawn frame.
App.tickDelta
ts
static readonly tickDelta: floatSeconds per tick: 1 / tps (this frame's dt in SYNC_WITH_FPS mode).
App.tick
ts
static readonly tick: intTicks run since start; during a tick handler, the index of that tick.
App.time
ts
static readonly time: floatScaled seconds since start, advanced per tick.
App.realTime
ts
static readonly realTime: floatUnscaled wall seconds since start.
App.tickAlpha
ts
static readonly tickAlpha: floatHow far the current frame is between the last tick and the next, 0 to 1.
App.actualTps
ts
static readonly actualTps: floatTicks per second measured over the last second.
App.actualFps
ts
static readonly actualFps: floatFrames per second measured over the last second.
App.maxCatchUpTicks
ts
static maxCatchUpTicks: intMost ticks run per frame to catch up (default 8); the excess is dropped.
App.droppedTicks
ts
static readonly droppedTicks: intTicks dropped because a frame needed more than maxCatchUpTicks.
App.maxFrameDelta
ts
static maxFrameDelta: floatThe longest dt the frame phase sees, in seconds (default 0.25).
App.timeScale
ts
static timeScale: floatScales App.time (default 1).
Other members of App
ts
static onFrame(handler: any): Function
static onQuit(handler: any): Function
static onResize(handler: any): Function
static onFocus(handler: any): Function
static onBlur(handler: any): Function
static quit(code?: int): voidAutotest static class
ts
static class AutotestHooks for thicket run --autotest scripts. Present in every program; outside --autotest nothing reads them.
Autotest.probe
ts
static probe(id: string, probe: () => boolean): voidNames a condition an autotest script can wait on: { "action": "wait_until", "probe": "<id>", "max": 600 } holds the script until probe returns true, checking once per frame for at most max frames (default 600), and fails the step if it never does. Registering the same id again replaces the probe.
System static class
ts
static class SystemProcess-level introspection and lifecycle. System is pre-bound in every scope (no import required) and is frozen at startup; its fields cannot be reassigned from script. It is a native static class at runtime.
System.capabilities
ts
readonly capabilities: SystemCapabilitiesFrozen host capabilities. Native-module fields describe modules embedded in this host, independent of project permissions. gamepad, fullscreen, and persistentStorage describe the current host's runtime ability; engine targets populate those meaningfully, while the headless tks CLI reports false.
System.debug
ts
readonly debug: SystemDebugRuntime stack-trace diagnostics.
System.audio
ts
readonly audio: anyDeprecated
Use the imported Audio static class.
System.DARWIN
ts
readonly DARWIN: stringPlatform constant: "darwin". Compare against System.platform().
System.LINUX
ts
readonly LINUX: stringPlatform constant: "linux". Compare against System.platform().
System.WIN32
ts
readonly WIN32: stringPlatform constant: "win32". Compare against System.platform().
System.WEB
ts
readonly WEB: stringPlatform constant: "web". Compare against System.platform().
System.args
ts
readonly args: string[]Command-line arguments passed to the script, in order. Does not include the interpreter path or the script path itself.
System.isPackaged
ts
readonly isPackaged: booleantrue when the program runs from a thicket build output (any strategy, release or not); false under thicket run. Set before the script starts, so it is readable at the top of a file.
System.cwd
ts
cwd(): stringCurrent working directory of the host process. Returns undefined if the underlying getcwd call fails.
System.storageDir
ts
storageDir(): stringThe app's persistent folder, for saves and settings. Created on first call. Needs no permission: an app always owns it, and Files reads and writes inside it pass without fs in thicket.json.
The folder is keyed by the app id (id in thicket.json, else the project folder's name). Linux $XDG_DATA_HOME or ~/.local/share/<id>; Windows %APPDATA%\<id>; macOS ~/Library/Application Support/<id>. Returns "" when no home folder is known.
System.cacheDir
ts
cacheDir(): stringThe app's cache folder, always safe to delete (compiled themes, baked fonts). Created on first call. Needs no permission, like storageDir(). Linux $XDG_CACHE_HOME or ~/.cache/<id>; Windows %LOCALAPPDATA%\<id>\Cache; macOS ~/Library/Caches/<id>. Returns "" when no home folder is known.
System.exit
ts
exit(code?: int): voidRequest process exit. Runs every registered onQuit handler before the host exits; the request is honored at the next safe point in the VM loop, so callers see the function return normally.
Example
ts
System.exit(0);System.frameDepth
ts
frameDepth(): intCurrent call-stack frame depth. Diagnostic.
System.gc
ts
gc(): intRun a garbage-collection cycle and return the number of objects freed.
System.instructions
ts
instructions(): float64Total instructions executed by the VM since startup. Returned as float64 because the count routinely exceeds the int32 range.
System.memUsage
ts
memUsage(): intBytes currently allocated by the VM (sum of live object sizes). Diagnostic.
System.objectCount
ts
objectCount(): intNumber of live VM objects. Diagnostic.
System.onFrame
ts
onFrame(handler: any): FunctionMigration alias for App.onFrame, retained for compatibility and scheduled for removal. Window hosts invoke it once per frame; console programs invoke it once per event-loop turn, after the preceding Promise microtasks.
System.onQuit
ts
onQuit(handler: any): voidRegister a callback to run during shutdown — after natural completion, System.exit(), or SIGINT/SIGTERM. Handlers run in registration order and are guaranteed to run at most once. Late registrations made while shutdown is already in progress are silently ignored.
System.platform
ts
platform(): stringHost platform: "darwin", "linux", "win32", "web", or "unknown" if the build was made on an unrecognized target. Equal to one of DARWIN/LINUX/WIN32/WEB by construction on supported platforms.
Example
ts
const os: string = System.platform();
console.log(os == "linux" || os == "darwin" || os == "win32" || os == "web"); // trueSystem.scriptPath
ts
scriptPath(): stringAbsolute path to the running script. Returns undefined when the VM was embedded without a script path (e.g. tks repl).
System.stackDepth
ts
stackDepth(): intCurrent operand-stack depth. Diagnostic.
System.time
ts
time(): float64Wall-clock time as milliseconds since the Unix epoch.
Example
ts
const msSinceEpoch: float64 = System.time();
console.log(msSinceEpoch > 0); // trueSystem.uptime
ts
uptime(): float64Milliseconds elapsed since process start, measured against the steady clock. Suitable for interval timing; not tied to wall-clock changes.
System.version
ts
version(): stringRuntime version string (e.g. "0.1.0").
Example
ts
console.log(System.version());SystemDebug class
ts
class SystemDebugType only: the runtime hands you instances; you never construct it yourself.
Diagnostic helpers exposed through System.debug.
SystemDebug.traceback
ts
traceback(): stringReturn the current ThicketScript call stack as a string.
SystemCapabilities class
ts
class SystemCapabilitiesType only: the runtime hands you instances; you never construct it yourself.
Frozen fields exposed by System.capabilities. All capability fields are present on every target so guarded branches type-check; their values report host availability, not permission grants.
SystemCapabilities.audio
ts
readonly audio: booleanNative audio module is embedded in this host.
SystemCapabilities.bitmap
ts
readonly bitmap: booleanNative bitmap module is embedded in this host.
SystemCapabilities.compress
ts
readonly compress: booleanNative compress module is embedded in this host.
SystemCapabilities.crypto
ts
readonly crypto: booleanNative crypto module is embedded in this host.
SystemCapabilities.database
ts
readonly database: booleanNative database module is embedded in this host.
SystemCapabilities.env
ts
readonly env: booleanNative env module is embedded in this host.
SystemCapabilities.events
ts
readonly events: booleanNative events module is embedded in this host.
SystemCapabilities.fs
ts
readonly fs: booleanNative fs module is embedded in this host.
SystemCapabilities.http
ts
readonly http: booleanNative http module is embedded in this host.
SystemCapabilities.net
ts
readonly net: booleanNative net module is embedded in this host.
SystemCapabilities.reactivity
ts
readonly reactivity: booleanThe reactivity script module is embedded in this host.
SystemCapabilities.shell
ts
readonly shell: booleanNative shell module is embedded in this host.
SystemCapabilities.terminal
ts
readonly terminal: booleanNative terminal module is embedded in this host.
SystemCapabilities.udp
ts
readonly udp: booleanNative udp module is embedded in this host.
SystemCapabilities.wsClient
ts
readonly wsClient: booleanThis host supports outbound WebSocket connections.
SystemCapabilities.wsServer
ts
readonly wsServer: booleanThis host supports listening for inbound WebSocket connections.
SystemCapabilities.ws
ts
readonly ws: booleanDeprecated
Use wsClient or wsServer; equivalent to wsClient || wsServer.
SystemCapabilities.engine
ts
readonly engine: booleanEngine component engine is linked into this host.
SystemCapabilities.willow
ts
readonly willow: booleanEngine component willow is linked into this host.
SystemCapabilities.gamepad
ts
readonly gamepad: booleanCurrent host can receive gamepad input; tks reports false.
SystemCapabilities.fullscreen
ts
readonly fullscreen: booleanCurrent host can enter fullscreen; tks reports false.
SystemCapabilities.persistentStorage
ts
readonly persistentStorage: booleanCurrent host offers persistent storage; tks reports false.
Generated from lang/types/system.d.tks in the ThicketScript repository.