Skip to main content

Crate mlua_check

Crate mlua_check 

Source
Expand description

Lua checker on mlua — undefined variable/global/field detection with LuaCats support.

Detects undefined variables, undefined globals, and undefined fields on known global tables. Designed to run before Lua execution, providing a safety net for AI-driven and programmatic Lua code generation.

§Quick start (one-shot)

let result = mlua_check::run_lint("print('hello')", "@main.lua", &[]).unwrap();
assert_eq!(result.diagnostics.len(), 0);

§Granular control (existing VM)

use mlua::prelude::*;
use mlua_check::register;

let lua = Lua::new();
// Register custom globals on the VM
let alc = lua.create_table().unwrap();
alc.set("llm", lua.create_function(|_, ()| Ok(())).unwrap()).unwrap();
lua.globals().set("alc", alc).unwrap();

// register() introspects the VM and builds a symbol table automatically
let engine = register(&lua).unwrap();
let result = engine.lint("alc.llm('hello')", "@main.lua");
assert_eq!(result.diagnostics.len(), 0);

let result = engine.lint("alc.unknown('hello')", "@main.lua");
assert!(result.warning_count > 0);

Re-exports§

pub use config::LintConfig;
pub use config::LintPolicy;
pub use engine::LintEngine;
pub use types::Diagnostic;
pub use types::LintResult;
pub use types::RuleId;
pub use types::Severity;
pub use vm::collect_symbols;
pub use vm::lint;
pub use vm::register;
pub use vm::register_with_config;
pub use vm::run_lint;

Modules§

config
engine
Top-level lint engine that coordinates parsing, rule execution, and result aggregation.
scope
symbols
types
vm
mlua VM integration — automatic symbol table construction from live VM state.