How snwfke/orbit works
Purpose and Delivery
Orbit is an alpha Zig-to-Lua microtranspiler aimed at selective, type-safe source translation for Lua-targeted environments such as DCS modding. It can be consumed as a Zig module or built as the orbit command-line executable. Build/package wiring is in build.zig; executable startup is src/main.zig; the library-facing module is likely src/orbit.zig.
Compilation Pipeline
The core flow is source file input → lexical tokens → parsed AST → Lua emission:
• CLI orchestration and input/output selection: src/main.zig
• Tokenization of Zig source: src/lexer.zig
• Syntax parsing and AST construction: src/parser.zig, src/ast.zig
• Lua generation from the internal representation: src/codegen.zig
This staged design establishes clear language boundaries: Zig source syntax is handled before code generation, and Lua-specific decisions are concentrated in the backend.
Front-End Representation
src/ast.zig defines the compiler’s intermediate syntax model shared between parser and generator. src/lexer.zig converts raw source text into tokens, while src/parser.zig validates supported Zig constructs and maps them into AST nodes. The AST is the principal contract: changes to supported language features generally require coordinated parser and code-generator updates.
Lua Backend
src/codegen.zig owns lowering supported Zig semantics into efficient Lua operations. The README identifies structs, enums, tables, constants, and imperative logic as important translation targets. Code generation is intentionally selective rather than attempting full Zig compatibility; unsupported compile-time, type-system, or runtime behavior should remain outside this backend’s semantic scope.
Public Integration Boundary
src/orbit.zig is the likely reusable library entry point exposed through the Zig build dependency/module pattern documented by the project. It should provide the stable API for embedding transpilation without invoking the CLI, while src/main.zig adapts command-line arguments such as input source (-F) and output Lua file (-o) to that library/compiler flow.
Runtime and Infrastructure
The implementation and build runtime are Zig 0.14.0, with build.zig producing the executable and module artifacts. Generated output targets Lua/Lua VM environments; there is no indicated server, database, or hosted external service dependency. Project language semantics and intended transpilation limits are documented in THEORY.md, with theory-oriented validation in src/test_theory.zig.
Main entry points: main.zig orbit CLI · orbit.zig Orbit module API · lexer.zig Lexer · parser.zig Parser
Components 10
Build & entry points
- Zig build wiring · Builds the CLI executable and reusable module.
build.zig - orbit CLI · Selects source input and Lua output from command-line arguments.
src/main.zig - Orbit module API · Embedding boundary for transpilation without the CLI.
src/orbit.zig
Zig front end
Lua backend
- Lua generator · Lowers supported Zig constructs into Lua operations.
src/codegen.zig - Lua output file · Output consumed by Lua VM environments.
- Language semantics · Defines intended translation limits and semantics.
THEORY.md
Connections 12
- Zig build wiring → orbit CLI: builds
- Zig build wiring → Orbit module API: exports
- orbit CLI → Orbit module API: invokes
- orbit CLI → Zig source file: selects with -F
- Orbit module API → Lexer: starts compilation
- Zig source file → Lexer: source text
- Lexer → Parser: tokens
- Parser → AST: constructs
- AST → Lua generator: lowers
- Lua generator → Lua output file: emits
- Language semantics → Parser: defines supported syntax
- Language semantics → Lua generator: guides semantics