# tecs ## Module contents ### Submodules | Submodule | Description | | --- | --- | | [`tecs.Application`](/modules/Application/) | The application lifecycle, entry plugin, frame, checkpoints, and crash state | | [`tecs.Future`](/modules/Future/) | Settle-once values, asynchronous composition, waiting, cancellation, and sequence tracking | | [`tecs.assets`](/modules/assets/) | Asynchronous byte, image, sound, and static glTF loading through futures | | [`tecs.audio`](/modules/audio/) | Clips, voices, groups, limits, entity sounds, snapshots, and audio devices | | [`tecs.data`](/modules/data/) | Typed stores, JSON, byte encodings, DEFLATE, text transcoding, UTF-8, UUIDs, hashes, and checksums | | [`tecs.ecs`](/modules/ecs/) | Worlds, entities, components, systems, plugins, queries, archetypes, phases, and resources | | [`tecs.events`](/modules/events/) | Typed event definitions and address-based message buses | | [`tecs.gfx`](/modules/gfx/) | 2D and 3D cameras, render components, meshes, the GPU renderer, images, shadows, and text | | [`tecs.input`](/modules/input/) | Gameplay input in three tiers behind a layer stack, with gamepads and standalone sensors | | [`tecs.io`](/modules/io/) | Binary I/O, nonblocking sockets, HTTP, files, and external tools | | [`tecs.log`](/modules/log/) | Named loggers, priority filtering, platform output, and JSON Lines files | | [`tecs.math`](/modules/math/) | Angle wrapping and shortest turns, with two-dimensional geometry beneath them. | | [`tecs.physics`](/modules/physics/) | Entity-first Rapier 2D rigid bodies, colliders, queries, contacts, sensors, and snapshots | | [`tecs.platform`](/modules/platform/) | Platform events, operating-system services, time, and windows | | [`tecs.regex`](/modules/regex/) | Compiled Rust regular expressions over Lua byte strings | | [`tecs.runtime`](/modules/runtime/) | Process-wide polling for asynchronous work in applications and headless programs | | [`tecs.sequence`](/modules/sequence/) | Snapshot-safe programs, waits, ownership, actions, and tween timelines | | [`tecs.ui`](/modules/ui/) | Retained layout, clipping, scrolling, and interaction for composed UI entities | | [`tecs.workers`](/modules/workers/) | Separate Lua states connected by serialized task and result channels | ### Constructors | Constructor | Description | | --- | --- | | [`newApplication`](/modules/#tecs.newApplication) | Builds the application an entry file returns. | ### Types | Type | Kind | Description | | --- | --- | --- | | [`Closeable`](/modules/#tecs.Closeable) | interface | An owned value that releases its active lifetime explicitly. | | [`Scope`](/modules/#tecs.Scope) | interface | Scope owns resources while preserving each concrete type. | ### Functions | Function | Kind | Description | | --- | --- | --- | | [`scoped`](/modules/#tecs.scoped) | Static | Runs a callback inside a fresh resource scope. | ### Values | Value | Type | Description | | --- | --- | --- | | [`version`](/modules/#tecs.version) | `string` | Read-only. Version of this build. | ## Constructors ### tecs.newApplication Static Builds the application an entry file returns. Not a function that runs until done: an entry file ends with `return tecs.newApplication(config)` and the host drives it from there, because a platform that never hands control back has no loop to block in. ```teal function tecs.newApplication( config: Application.Config ): Application ``` #### Arguments | Name | Type | Description | | --- | --- | --- | | `config` | [`Application.Config`](/modules/Application/#tecs.Application.Config) | Read here, so a field changed on the table afterwards is not seen. Nothing is opened yet: the window, the GPU device and the audio mixer are the host's to bring up on the first callback, which is what lets an entry file be loaded by a tool that never runs one. | #### Returns | Type | Description | | --- | --- | | [`Application`](/modules/Application/) | The application the host drives through its init, event, iterate and quit callbacks. Returning it is the whole contract; a game that calls into it itself is doing the host's job. | ## Types ### tecs.Closeable interface An owned value that releases its active lifetime explicitly. `close` may report a delayed finalization failure. Every implementation returns true on success. Its own contract defines whether repeated calls are safe. ```teal interface tecs.Closeable close: function(self): boolean, string end ``` #### tecs.Closeable:close Instance Releases the value's active lifetime. ```teal function tecs.Closeable.close(self): boolean, string ``` ##### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `Closeable` | The value to close. | ##### Returns | Type | Description | | --- | --- | | `boolean` | Returns true when finalization succeeds. | | `string` | Returns a finalization reason when the first return is false. | #### Examples ```teal local destination = tecs.io.newFileStream("save.bin") local writer = assert(destination:newWriter()) assert(writer:write("complete")) assert(writer:close()) destination:close() ``` ### tecs.Scope interface `Scope` owns resources while preserving each concrete type. ```teal interface tecs.Scope own: function(self, value: T, reason: string): T end ``` #### tecs.Scope:own Instance Registers one owned value for cleanup and returns it unchanged. The scope is active only inside the callback passed to `scoped`. Calling a captured scope after that callback returns, raises, or begins cleanup raises instead of creating an ownership obligation nobody will run. Passing nil raises with `reason` when one is supplied, which lets a constructor's `value, reason` result pass directly to `own`. Without a supplied reason, or with a value that has no `close` method, `own` raises its own argument error. ```teal function tecs.Scope.own( self, value: T, reason: string ): T ``` ##### Type Parameters | Name | Constraint | Description | | --- | --- | --- | | `T` | [`Closeable`](/modules/#tecs.Closeable) | | ##### Arguments | Name | Type | Description | | --- | --- | --- | | `self` | `Scope` | The active scope that will own the value. | | `value` | `T` | An open [`Closeable`](/modules/#tecs.Closeable) or Lua file. Each call adds one cleanup obligation, including repeated calls with the same value. | | `reason` | `string` | The operational failure returned beside a nil value. `own` raises this string at the call site. | ##### Returns | Type | Description | | --- | --- | | `T` | The same value with its concrete type unchanged. | ## Functions ### tecs.scoped Static Runs a callback inside a fresh resource scope. The callback runs synchronously and must not yield. Every value it registers closes in reverse order before this function returns or propagates a failure. Cleanup begins by making the scope inactive, and one failing close does not prevent the remaining closes. ```teal function tecs.scoped(body: function(Scope)) ``` #### Arguments | Name | Type | Description | | --- | --- | --- | | `body` | `function(`[`Scope`](/modules/#tecs.Scope)`)` | The callback that receives the only active [`Scope`](/modules/#tecs.Scope) for this invocation. Returned values are ignored, and registered resources must not be used after the callback ends. | #### Returns None. ## Values ### tecs.version variable Read-only. Version of this build. ```teal tecs.version: string ```