luau-analyzer-sys 0.1.0

A high-performance, embedded Luau type-checking and analysis engine written in Rust. This crate provides bindings to the Luau analyzer, allowing you to integrate static analysis and code intelligence directly into your applications.
docs.rs failed to build luau-analyzer-sys-0.1.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: luau-analyzer-sys-0.1.1

luau-analyzer-sys

High-level ergonomic Rust bindings and low-level C++ FFI bindings for the native Luau static type analyzer and compiler frontend.

License: MIT Rust

Overview

luau-analyzer-sys provides a bridge between Rust and Luau's C++ static type checking engine (Luau::Frontend). It abstracts away internal type resolution scopes, AST traversal checks, and linting routines into a safe, easy-to-use Rust interface (NativeAnalyzer).

Key Features

  • Embedded Type Analysis: Perform zero-overhead static checking of Luau codebases directly from Rust.
  • Custom Definitions: Inject global environment mapping definitions dynamically via Luau .d.luau files.
  • Dependency Resolution: Fully recursive module path resolution via safe Rust closures.
  • Granular Diagnostics: Capture detailed warnings, errors, and lint output complete with source span offsets.
  • Deprecation Linting: Native static interception of deprecated functions (e.g. getfenv) mapped via dynamic line deduplication.

Usage

Add luau-analyzer-sys as a dependency in your Cargo.toml:

[dependencies]

luau-analyzer-sys = { path = "../luau-analyzer-sys" }

Example: Checking a Luau Module

use luau_analyzer_sys::NativeAnalyzer;

fn main() {
    let mut analyzer = NativeAnalyzer::new();

    // 1. Inject global type definitions
    analyzer.add_definitions(r#"
declare task: {
    spawn: (...any) -> thread
}
"#);

    // 2. Check source code using a recursive string-resolving closure
    let source = "task.spawn(function() print('Checking native type structures') end)";
    let diagnostics = analyzer.check("main.luau", |module_name| {
        if module_name == "main.luau" {
            Some(source.to_string())
        } else {
            None
        }
    });

    if diagnostics.is_empty() {
        println!("Type checking completed successfully with zero errors.");
    } else {
        for diag in diagnostics {
            let severity = if diag.severity == 0 { "error" } else { "warning" };
            println!("{}: {} at line {}:{}", severity, diag.message, diag.line + 1, diag.col + 1);
        }
    }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.