Crate darklua_core

Crate darklua_core 

Source
Expand description

Darklua is a utility for transforming and processing Lua and Luau code. It provides a set of tools for parsing and modifying Lua/Luau code.

If you are looking for a command-line tool, please visit darklua.com or github.com/seaofvoices/darklua for installation and usage instructions.

This documentation site is for the darklua library itself.

§Library Usage

To start using darklua in your own project, add the following to your Cargo.toml file:

[dependencies]
darklua = "0.17.1"

This library is designed for developers who want to integrate Lua/Luau transformation capabilities into their own applications.

Please note that the library is developed primarily for the darklua command line tool. There may be some rough edges, but it should be stable enough for most use cases.

§Running Darklua in Memory

The following example shows how to run darklua in memory, without writing to the file system.

Note that the library name is darklua_core and not darklua.

use std::path::Path;
use darklua_core::{Configuration, Options, Resources, rules::{RemoveEmptyDo, Rule}};

let resources = Resources::from_memory();
resources.write("project-path/src/main.lua", "do end print('Hello, world!')");
let input_path = Path::new("project-path/src");

let remove_empty_do: Box<dyn Rule> = Box::new(RemoveEmptyDo::default());
let config = Configuration::empty().with_rule(remove_empty_do);

let process_result = darklua_core::process(
    &resources,
    Options::new(&input_path)
        .with_configuration(config),
);

process_result.expect("failed to process with darklua");

assert_eq!(
    resources.get("project-path/src/main.lua").expect("failed to get output"),
    "print('Hello, world!')"
);

Modules§

generator
A module that contains the main LuaGenerator trait and its implementations.
nodes
The collection of nodes used for the Lua abstract syntax tree.
process
Defines how rules can process and mutate Lua nodes.
rules
A module that contains the different rules that mutates a Lua/Luau block.

Structs§

BundleConfiguration
Configuration for bundling modules.
Configuration
Configuration for processing files (rules, generator, bundling).
DarkluaError
The main error type for the darklua library.
Options
Options for configuring the darklua process function. This is not the Configuration data itself.
Parser
A parser for Luau code that converts it into an abstract syntax tree.
ParserError
The error type that can occur when parsing code.
Resources
A resource manager for handling file operations.
WorkerTree
A structure that manages the processing of Lua/Luau files and their dependencies.

Enums§

GeneratorParameters
Parameters for configuring the Lua code generator.

Functions§

convert_data
Convert serializable data into a Lua module.
process
Process resources according to the given options.