Files
benilla-octo/crates/benilla-ui/examples/dump_globals.rs
T
Sam SungandClaude Opus 5.5 5b92f94d5c Comments in benilla-ui: one line of fact each, no history, no record numbers (#143)
Part of #41: the comments of `benilla-ui` (the Lua UI engine, its FrameXML loader and its widgets) are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 43,140 comment lines become 15,161.

- **The mechanical strip.** The citations that were only a private record number go first, and each edit is shown to be a pure removal.
- **Wrong facts corrected.** The rewrite corrects the comments that stated wrong facts. Among them:
  - `0x64a480` is the case-sensitive compare (a byte `repz cmpsb`), and `0x64a4c0` the case-insensitive one.
  - A frame's id sits at `+0xb0`, not `+0xb4`. `EnableKeyboard`/`IsKeyboardEnabled` are `0x776ec0`/`0x776f90`.
  - A region's unpinned edge has no fallback to its owner's rect: the owner supplies only the scale.
  - `$parent` expands to the nearest named ancestor, or "Top" when none is named (`0x76c5b0`), not simply to the parent.
  - A StatusBar fills from its internal normalised fraction, not from `GetValue()`.
  - The addresses of `StartDuel` and `StartDuelUnit` were swapped.
  - Many "untraced" notes now give the traced reference fact: the drag threshold, the per-grip sizing edges, the empty-`autoFocus` skip, and `SetTexCoordModifiesRect`'s default.
  - Stock FrameXML line citations are checked against the stock 1.12 files and corrected. `ref-` file names become the stock file names.
- **Deviation labels.** "Deviation:" now marks only a choice with a reason. A surface that exists only for the retired Era addon target says so plainly: it is not 1.12.
- **Verification.** Every file strips to identical code, and `cargo fmt --check` is clean. Nine second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the code, the stock files, vmangos and the reference.

Behaviour differences the rewrite surfaced are filed as their own issues (#131–#142), and more are being validated. The comments here state what the code does. String literals are untouched; they are #92.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 01:58:49 +07:00

70 lines
2.7 KiB
Rust

//! `dump_globals`: print benilla's Lua global namespace, asked of a real VM.
//!
//! ```text
//! cargo run -q -p benilla-ui --example dump_globals # name<TAB>type, one per line
//! cargo run -q -p benilla-ui --example dump_globals --members # plus the stdlib tables' members
//! ```
//!
//! The namespace is [`UiScript::new`]'s, the engine half before any FrameXML loads, which
//! `scripts/api-coverage.sh` compares with `reference/1.12-globals.tsv`. `--members` adds what `_G`
//! cannot show: the stdlib tables' members (`table.setn` is one) and the per-type metatables.
use benilla_ui::script::UiScript;
/// The stdlib tables whose members an addon can observe: a fixed list, since `_G` would recurse
/// and a frame's members are the widget API.
const STDLIB: &[&str] = &["string", "table", "math", "coroutine", "os", "io", "debug"];
fn main() -> mlua::Result<()> {
let script = UiScript::new()?;
// Joined Lua-side into one `name<TAB>type` string per entry: a `Vec<String>` crosses the mlua
// boundary directly, where a `Vec<(String, String)>` does not.
let mut rows: Vec<String> = script.eval(
"local out = {} \
for k, v in pairs(_G) do \
if type(k) == 'string' then table.insert(out, k .. '\\t' .. type(v)) end \
end \
return out",
)?;
if std::env::args().any(|a| a == "--members") {
for lib in STDLIB {
let members: Vec<String> = script.eval(&format!(
"local t = {lib} \
local out = {{}} \
if type(t) == 'table' then \
for k, v in pairs(t) do \
if type(k) == 'string' then \
table.insert(out, '{lib}.' .. k .. '\\t' .. type(v)) \
end \
end \
end \
return out"
))?;
rows.extend(members);
}
// The per-type metatables. Every row should read `nil`: 1.12's `lua_setmetatable`
// (`0x6f4020`) takes only tables and userdata, where 5.1 gives strings one whose `__index`
// makes `("x"):upper()` work. Probed one by one, since a `nil` has no table entry.
let metatables: Vec<String> = script.eval(
"local out = {} \
local function probe(name, v) \
table.insert(out, '<' .. name .. '>\\tmetatable ' .. type(getmetatable(v))) \
end \
probe('string', '') \
probe('number', 0) \
probe('boolean', true) \
probe('nil', nil) \
probe('function', probe) \
return out",
)?;
rows.extend(metatables);
}
rows.sort();
for row in rows {
println!("{row}");
}
Ok(())
}