darklua_core/
lib.rs

1//! Darklua is a utility for transforming and processing Lua and Luau code. It provides
2//! a set of tools for parsing and modifying Lua/Luau code.
3//!
4//! If you are looking for a command-line tool, please visit [darklua.com](https://darklua.com/docs/installation/)
5//! or [github.com/seaofvoices/darklua](https://github.com/seaofvoices/darklua)
6//! for installation and usage instructions.
7//!
8//! This documentation site is for the darklua library itself.
9//!
10//! # Library Usage
11//!
12//! To start using darklua in your own project, add the following to your `Cargo.toml` file:
13//!
14//! ```toml
15//! [dependencies]
16//! darklua = "0.17.1"
17//! ```
18//!
19//! This library is designed for developers who want to integrate Lua/Luau transformation capabilities
20//! into their own applications.
21//!
22//! Please note that the library is developed primarily for the darklua command line tool. There may be
23//! some rough edges, but it should be stable enough for most use cases.
24//!
25//! # Running Darklua in Memory
26//!
27//! The following example shows how to run darklua in memory, without writing to the file system.
28//!
29//! Note that the library name is `darklua_core` and **not** `darklua`.
30//!
31//! ```rust
32//! use std::path::Path;
33//! use darklua_core::{Configuration, Options, Resources, rules::{RemoveEmptyDo, Rule}};
34//!
35//! let resources = Resources::from_memory();
36//! resources.write("project-path/src/main.lua", "do end print('Hello, world!')");
37//! let input_path = Path::new("project-path/src");
38//!
39//! let remove_empty_do: Box<dyn Rule> = Box::new(RemoveEmptyDo::default());
40//! let config = Configuration::empty().with_rule(remove_empty_do);
41//!
42//! let process_result = darklua_core::process(
43//!     &resources,
44//!     Options::new(&input_path)
45//!         .with_configuration(config),
46//! );
47//!
48//! process_result.expect("failed to process with darklua");
49//!
50//! assert_eq!(
51//!     resources.get("project-path/src/main.lua").expect("failed to get output"),
52//!     "print('Hello, world!')"
53//! );
54//! ```
55
56mod ast_converter;
57mod frontend;
58pub mod generator;
59pub mod nodes;
60mod parser;
61pub mod process;
62pub mod rules;
63mod utils;
64
65pub use frontend::{
66    convert_data, process, BundleConfiguration, Configuration, DarkluaError, GeneratorParameters,
67    Options, Resources, WorkerTree,
68};
69pub use parser::{Parser, ParserError};