Lua checker on mlua — undefined variable / global / field detection with LuaCats support.
Designed to run before Lua execution, providing a safety net for AI-driven and programmatic Lua code generation.
- Undefined variable — reference to a variable not defined in any enclosing scope
- Undefined global — reference to a global name not in the known symbol table
- Undefined field — access to a field not declared in a
---@classdefinition - Unused variable — a local variable that is declared but never referenced
- VM introspection — automatically builds symbol table from live
mluaglobals
let result = mlua_check::run_lint("print('hello')", "@main.lua").unwrap();
assert_eq!(result.diagnostics.len(), 0);use mlua::prelude::*;
use mlua_check::register;
let lua = Lua::new();
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);use mlua_check::{LintConfig, LintPolicy};
let config = LintConfig::default().with_policy(LintPolicy::Strict);| Policy | Behavior |
|---|---|
Strict |
Lint errors block execution |
Warn |
Issues reported, execution proceeds (default) |
Off |
Linting disabled |
Licensed under either of
at your option.