mlua_check/lib.rs
1//! Lua checker on mlua — undefined variable/global/field detection with LuaCats support.
2//!
3//! Detects undefined variables, undefined globals, and undefined fields
4//! on known global tables. Designed to run **before** Lua execution,
5//! providing a safety net for AI-driven and programmatic Lua code generation.
6//!
7//! # Quick start (one-shot)
8//!
9//! ```rust
10//! let result = mlua_check::run_lint("print('hello')", "@main.lua", &[]).unwrap();
11//! assert_eq!(result.diagnostics.len(), 0);
12//! ```
13//!
14//! # Granular control (existing VM)
15//!
16//! ```rust
17//! use mlua::prelude::*;
18//! use mlua_check::register;
19//!
20//! let lua = Lua::new();
21//! // Register custom globals on the VM
22//! let alc = lua.create_table().unwrap();
23//! alc.set("llm", lua.create_function(|_, ()| Ok(())).unwrap()).unwrap();
24//! lua.globals().set("alc", alc).unwrap();
25//!
26//! // register() introspects the VM and builds a symbol table automatically
27//! let engine = register(&lua).unwrap();
28//! let result = engine.lint("alc.llm('hello')", "@main.lua");
29//! assert_eq!(result.diagnostics.len(), 0);
30//!
31//! let result = engine.lint("alc.unknown('hello')", "@main.lua");
32//! assert!(result.warning_count > 0);
33//! ```
34
35pub mod config;
36pub mod engine;
37mod rules;
38pub mod scope;
39pub mod symbols;
40pub mod types;
41pub mod vm;
42mod walker;
43
44pub use config::{LintConfig, LintPolicy};
45pub use engine::LintEngine;
46pub use types::{Diagnostic, LintResult, RuleId, Severity};
47pub use vm::{collect_symbols, lint, register, register_with_config, run_lint};