Skip to content

Camilo-Camargo/lony

Repository files navigation

Lony

A cross-platform UI framework where .lony files compile to native apps. One language, one codebase -- runs on Web, macOS, iOS, Android, and Linux.

.lony source --> lonyc (compiler) --> binary IR (.lonybin) --> C runtime (SDL3)

Quick Start

# 1. Build the compiler
make compiler

# 2. Create a new project
lonyc init my_app --path examples

# 3. Run on your platform
make run-macos                              # macOS (Vulkan/MoltenVK)
make run-ios                                # iOS Simulator
make run-android                            # Android device/emulator
make run-wasm                               # Browser (WebGPU + hotreload)
make run-linux                              # Linux

Use a different example:

make run-macos EXAMPLE=examples/my_app/App.lony

The Language

Lony uses the SAVE pattern: State, Action, View, Error.

Component Counter() {
    State {
        count: int = 0
    }

    Action increment(): void {
        count = count + 1
    }

    Action decrement(): void {
        count = count - 1
    }

    View {
        Flex(direction="column", align_items="center", gap=16, padding=20) {
            Text("Counter", fontSize=32)
            Text(count, fontSize=48)

            Flex(direction="row", gap=12) {
                Button("-", onClick=decrement)
                Button("+", onClick=increment)
            }
        }
    }
}

Multi-Screen Apps

import Welcome from components.Welcome
import Counter from components.Counter

Routes {
    "/": Welcome
    "/counter": Counter
}

Component App() {
    View {
        Router.Outlet()
    }
}

Async Data Fetching

Component ApiFetch() {
    State {
        title: string = "Press to fetch"
    }

    Action fetchPost(): void {
        response = await fetch("https://jsonplaceholder.typicode.com/posts/1")
        data = response.json()
        title = data.title
    }

    View {
        Flex(direction="column", align_items="center", gap=16, padding=20) {
            Text(title, fontSize=18)
            Button("Fetch", onClick=fetchPost)
        }
    }
}

UI Elements

Layout Input Display Data Overlay
Flex Button Text Table Dialog
ScrollView Input Image ProgressBar Toast
Divider TextArea Avatar
Tabs Checkbox VideoPlayer
Toggle Shader
Slider
Select
Radio

Key Capabilities

  • Reactive state -- state variables automatically update the UI
  • Async actions -- await fetch() with built-in JSON parsing
  • Flexbox layout -- direction, gap, padding, justify_content, align_items
  • Routing -- Routes + Router.navigate() for multi-screen apps
  • Components -- import and compose reusable components
  • Themes -- theme.lony for shared styles
  • Native modules -- extend with platform-specific C code
  • Hotreload -- instant updates during development

Project Structure

cli/compiler/             Rust compiler (lonyc) -- parses .lony, emits binary IR
engine/
  common/src/             C runtime -- loads IR, renders via SDL3
    core/                 Runtime, IR loader, draw, actions, components, arena allocator
    layout/               Flexbox layout engine
    renderer/             Vulkan, WebGPU, OpenGL ES backends
    hotreload/            Platform-specific hotreload clients
    state/                Global state store + action execution
    net/                  HTTP + WebSocket (native: mbedTLS; WASM: browser APIs)
    media/                Image, video, audio, camera, microphone
    std/storage/          File persistence (all platforms + WASM IDBFS)
  wasm/                   Emscripten build scripts
  macos/                  Xcode project
  ios/                    Xcode project
  android/                Gradle + CMake
  linux/                  Linux build + cross-compilation (via zig)
lsp/                      Language server (Rust)
lony-vscode/              VS Code extension
examples/                 Example apps
docs/                     Standard library and module docs

CLI Reference

Project Commands

lonyc init <name> [--path <dir>]                      # Scaffold a new project
lonyc build -i <input.lony> -o <dir> -t <target>      # Compile to IR or other targets
lonyc serve -i <input.lony>                            # Hotreload server (TCP + WebSocket)
lonyc watch -i <dir> -t <target>                       # Watch and rebuild on changes
lonyc dev -i <input.lony> -p <platforms>               # Multi-platform dev mode
lonyc check <input.lony>                               # Type-check only
lonyc run <input.lony> -t <macos|ios|android|wasm>     # Build + run on platform

Native Modules

lonyc create-module <name> --project <dir>             # Create module
lonyc create-module <name> --project <dir> --cmake     # Create CMake module
lonyc build-module <name> --project <dir> -t all       # Build for all platforms
lonyc delete-module <name> --project <dir>             # Remove module
lonyc sync                                             # Sync modules into platform builds

Make Targets

# Build
make compiler                     # Build lonyc (release), links to ~/.cargo/bin/lonyc
make build-all                    # Full clean + compiler build
make clean                        # Clean all build artifacts

# Run
make run-macos                    # macOS
make run-ios                      # iOS Simulator
make run-ios-device TEAM_ID=XXX   # iOS real device
make run-android                  # Android
make run-wasm                     # WASM + hotreload + HTTP server
make run-linux                    # Linux native
make serve                        # Hotreload server only

# Cross-compilation (macOS to Linux x86_64 via zig)
make cross-build-linux            # Software renderer
make cross-build-linux-minimal    # Minimal (no FFmpeg/shaders/SVG)
make deploy-linux                 # Cross-compile + deploy to QEMU VM

# Logs
make logs-runtime LOG_PLATFORM=macos
make logs-runtime LOG_PLATFORM=android
make logs-runtime LOG_PLATFORM=ios
make logs-help                    # All log commands

How It Works

  1. Parse: lonyc parses .lony files using a PEG grammar into an AST
  2. Compile: The AST is serialized into a compact binary IR (.lonybin)
  3. Load: The C runtime loads the IR at startup or receives it via hotreload
  4. Layout: A flexbox engine computes positions and sizes for the component tree
  5. Render: SDL3 draws to screen using Vulkan (native), WebGPU (WASM), or OpenGL ES (iOS sim)
  6. React: State changes trigger re-layout and re-render

Development

Testing

cd cli/compiler && cargo test             # Compiler tests
cd cli/compiler && cargo test <test>      # Single test

Hotreload Flow

  1. lonyc serve watches .lony files, recompiles IR on change
  2. Pushes new .lonybin over TCP (native) or WebSocket (WASM)
  3. Runtime clears registries, rebuilds component tree from new IR
  4. print() in actions sends logs back to the server

Editor Support

Install the Lony extension for VS Code from lony-vscode/. It provides syntax highlighting and language server integration via the LSP in lsp/.

Standard Libraries

  • std.router -- client-side routing (Router.navigate(), Router.Outlet())
  • std.storage -- app-local file persistence on all platforms (see docs/std/storage.md)

Documentation

  • Language specification: LONY_LANGUAGE.md
  • Module system: docs/modules/
  • Standard library: docs/std/

Prerequisites

  • Rust -- compiler
  • Xcode -- macOS and iOS builds
  • Android SDK + NDK -- Android builds
  • Emscripten -- WASM builds
  • Python 3 -- WASM dev server
  • zig (optional) -- Linux cross-compilation from macOS

License

MIT License -- see LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors