Files
benilla-octo/crates/benilla-ui/src/script/surface.rs
T
Sam SungandClaude Opus 5.5 fd386e75ae 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

163 lines
5.7 KiB
Rust

//! benilla's widget method surface asked of a running VM, shared by the `dump_widget_methods`
//! example and the widget-surface gate (`script::tests::widget_surface`). Each row is a live
//! instance asked `type(obj.Name) == "function"`, as an addon asks it; only the candidate names
//! come from elsewhere, the keys of the VM's method tables ([`METHOD_TABLES`]), since a Rust
//! `__index` dispatcher cannot be enumerated from Lua.
use std::collections::BTreeSet;
use mlua::{Table, Value};
use super::UiScript;
/// The VM's named-registry method tables: every widget method benilla registers is a key in one,
/// and the per-instance probe decides which a class answers.
const METHOD_TABLES: &[&str] = &[
"__benilla_frame_methods",
"__benilla_region_methods",
"__benilla_texture_methods",
"__benilla_fontstring_methods",
"__benilla_title_methods",
"__benilla_font_methods",
"__benilla_button_methods",
"__benilla_checkbutton_methods",
"__benilla_lootbutton_methods",
"__benilla_editbox_methods",
"__benilla_statusbar_methods",
"__benilla_slider_methods",
"__benilla_scrollframe_methods",
"__benilla_simplehtml_methods",
"__benilla_colorselect_methods",
"__benilla_model_methods",
"__benilla_playermodel_methods",
"__benilla_dressupmodel_methods",
"__benilla_tabardmodel_methods",
"__benilla_plain_messageframe_methods",
"__benilla_scrollingmessageframe_methods",
"__benilla_minimap_methods",
"__benilla_tooltip_methods",
];
/// Every class benilla can hand an addon, with a Lua expression making one, published as
/// `DW_<Class>`. `Frame` must come first: the region and font rows are made by it.
/// `TaxiRouteFrame` is left out, being a plain `Frame` to Lua.
const CLASSES: &[(&str, &str)] = &[
("Frame", r#"CreateFrame("Frame", "DWFrameN", UIParent)"#),
(
"WorldFrame",
r#"CreateFrame("WorldFrame", "DWWorldN", UIParent)"#,
),
("Button", r#"CreateFrame("Button", "DWButtonN", UIParent)"#),
(
"LootButton",
r#"CreateFrame("LootButton", "DWLootN", UIParent)"#,
),
(
"CheckButton",
r#"CreateFrame("CheckButton", "DWCheckN", UIParent)"#,
),
("EditBox", r#"CreateFrame("EditBox", "DWEditN", UIParent)"#),
(
"StatusBar",
r#"CreateFrame("StatusBar", "DWStatusN", UIParent)"#,
),
("Slider", r#"CreateFrame("Slider", "DWSliderN", UIParent)"#),
(
"ScrollFrame",
r#"CreateFrame("ScrollFrame", "DWScrollN", UIParent)"#,
),
("Model", r#"CreateFrame("Model", "DWModelN", UIParent)"#),
(
"PlayerModel",
r#"CreateFrame("PlayerModel", "DWPlayerModelN", UIParent)"#,
),
(
"DressUpModel",
r#"CreateFrame("DressUpModel", "DWDressN", UIParent)"#,
),
(
"TabardModel",
r#"CreateFrame("TabardModel", "DWTabardN", UIParent)"#,
),
(
"MessageFrame",
r#"CreateFrame("MessageFrame", "DWMessageN", UIParent)"#,
),
(
"ScrollingMessageFrame",
r#"CreateFrame("ScrollingMessageFrame", "DWScrollMsgN", UIParent)"#,
),
(
"ColorSelect",
r#"CreateFrame("ColorSelect", "DWColorN", UIParent)"#,
),
(
"SimpleHTML",
r#"CreateFrame("SimpleHTML", "DWHtmlN", UIParent)"#,
),
(
"MovieFrame",
r#"CreateFrame("MovieFrame", "DWMovieN", UIParent)"#,
),
(
"GameTooltip",
r#"CreateFrame("GameTooltip", "DWTooltipN", UIParent)"#,
),
(
"Minimap",
r#"CreateFrame("Minimap", "DWMinimapN", UIParent)"#,
),
("Texture", r#"DW_Frame:CreateTexture("DWTexN")"#),
("FontString", r#"DW_Frame:CreateFontString("DWFSN")"#),
("TitleRegion", r#"DW_Frame:CreateTitleRegion()"#),
("Font", r#"CreateFont("DWFontN")"#),
];
/// Every `(class, method)` pair this VM answers, one live instance per class. A class that cannot
/// be made reports `(class, "!NOT-INSTANTIABLE")` rather than dropping out.
pub fn widget_method_census(script: &UiScript) -> mlua::Result<Vec<(String, String)>> {
let mut candidates: BTreeSet<String> = BTreeSet::new();
for key in METHOD_TABLES {
let table: Table = script.lua().named_registry_value(key).map_err(|e| {
mlua::Error::runtime(format!(
"candidate source '{key}' is not a table in this VM ({e}) — a renamed or retired \
method table would silently shrink this census; fix the list, do not ignore it"
))
})?;
for pair in table.pairs::<Value, Value>() {
let (k, _) = pair?;
if let Value::String(s) = k {
candidates.insert(s.to_str()?.to_string());
}
}
}
// Hand the names to the VM once; the per-class probe is then one chunk, not one per name.
let names = script.lua().create_table()?;
for (i, n) in candidates.iter().enumerate() {
names.set(i + 1, n.as_str())?;
}
script.lua().globals().set("DW_NAMES", names)?;
let mut rows: Vec<(String, String)> = Vec::new();
for (class, expr) in CLASSES {
if let Err(e) = script.run(&format!("DW_{class} = {expr}")) {
eprintln!("{class}: could not be instantiated: {e}");
rows.push(((*class).to_string(), "!NOT-INSTANTIABLE".to_string()));
continue;
}
let found: Vec<String> = script.eval(&format!(
"local o = DW_{class} \
local out = {{}} \
for i = 1, table.getn(DW_NAMES) do \
local n = DW_NAMES[i] \
if type(o[n]) == 'function' then table.insert(out, n) end \
end \
return out"
))?;
for name in found {
rows.push(((*class).to_string(), name));
}
}
rows.sort();
Ok(rows)
}