Skip to main content

Install the main package

Loretta is distributed via NuGet as Loretta.CodeAnalysis.Lua. This package contains the core parsing, analysis, and transformation APIs you need to work with Lua code.
dotnet add package Loretta.CodeAnalysis.Lua
The version number shown is the current stable release. Check NuGet for the latest version.

Experimental package (optional)

For access to experimental features like the constant folder and minifier, install the experimental package:
dotnet add package Loretta.CodeAnalysis.Lua.Experimental
APIs in the experimental package may change between releases. Use these features in production with caution.

System requirements

Loretta supports the following .NET platforms:
  • .NET 8.0 or later
  • .NET Standard 2.0 (compatible with .NET Framework 4.6.1+, .NET Core 2.0+, Mono, Xamarin, and Unity)
The library works across Windows, macOS, and Linux.

Verify installation

After installing the package, verify it’s working by adding this code to your project:
using Loretta.CodeAnalysis.Lua;

var code = "print('Hello from Loretta!')";
var tree = LuaSyntaxTree.ParseText(code);
var root = tree.GetRoot();

Console.WriteLine($"Parsed {root.DescendantNodes().Count()} nodes");
If this compiles and runs without errors, Loretta is installed correctly.

Package contents

Loretta.CodeAnalysis.Lua

The main package includes:
  • Lexer - Tokenizes Lua source code
  • Parser - Builds syntax trees from tokens
  • Syntax tree APIs - Navigate and inspect parsed code
  • Syntax factory - Generate Lua code programmatically
  • Rewriter APIs - Transform syntax trees
  • Diagnostics - Error and warning reporting
  • Parse options - Configure Lua version and dialect support
Key namespaces:
  • Loretta.CodeAnalysis.Lua - Core types and entry points
  • Loretta.CodeAnalysis.Lua.Syntax - Syntax node types
  • Loretta.CodeAnalysis.Text - Source text handling

Loretta.CodeAnalysis.Lua.Experimental

The experimental package adds:
  • Constant folder - Evaluate and fold constant expressions
  • Minifier - Remove unnecessary whitespace and comments
  • Additional transformations - Experimental code transformation utilities
These features are under active development and their APIs may change.

Target framework selection

Loretta multi-targets .NET 8.0 and .NET Standard 2.0:
  • For modern .NET projects (.NET 6+): You automatically get the .NET 8.0 version with improved performance and reduced allocations
  • For .NET Framework or older .NET Core: You automatically get the .NET Standard 2.0 version with broader compatibility
The NuGet package manager selects the appropriate version based on your project’s target framework.

Next steps

Quickstart

Parse your first Lua code in under 5 minutes

Introduction

Learn what Loretta can do

Build docs developers (and LLMs) love