From 783a8ba951615af71bc485148b6b24f2c5da98c2 Mon Sep 17 00:00:00 2001 From: chairmanpow Date: Sun, 4 Oct 2026 15:59:40 +0100 Subject: [PATCH] ui: define TurtleWoW's sizeof so Transmog/Shop windows do not raise on nil --- crates/benilla-ui/src/script/stdlib.rs | 18 ++++++++++++++++++ .../src/script/tests/reference_surface.rs | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/crates/benilla-ui/src/script/stdlib.rs b/crates/benilla-ui/src/script/stdlib.rs index bd108152..8d166045 100644 --- a/crates/benilla-ui/src/script/stdlib.rs +++ b/crates/benilla-ui/src/script/stdlib.rs @@ -397,6 +397,24 @@ do local trimmed = _gsub(str, "^%s*(.-)%s*$", "%1") return trimmed end + + -- `sizeof(t)`: TurtleWoW's `Globals.lua:111` table-entry count. Its patched FrameXML uses it + -- wherever a list's length is wanted — `Turtle_TransmogUI.lua:677` counts + -- `AvailableTransmogItems[InventorySlotId]`, its `TransmogOutfits` pages, `OptionsFrame.lua` + -- the arena-team rows, and `Blizzard_BindingUI` the search results. 1.12 has no such name + -- (`reference/1.12-globals.tsv` is silent and no stock file calls it); the exception list in + -- `tests/reference_surface.rs` carries the same reason. The body is the reference's verbatim: + -- a non-table is 0, and `pairs` counts every key, hash and array. + function sizeof(t) + if type(t) ~= "table" then + return 0 + end + local s = 0 + for k in pairs(t) do + s = s + 1 + end + return s + end end -- ── NOT here: tostringall / strconcat / strtrim ──────────────────────────────────────────────── diff --git a/crates/benilla-ui/src/script/tests/reference_surface.rs b/crates/benilla-ui/src/script/tests/reference_surface.rs index f8d10286..34352539 100644 --- a/crates/benilla-ui/src/script/tests/reference_surface.rs +++ b/crates/benilla-ui/src/script/tests/reference_surface.rs @@ -43,6 +43,11 @@ fn allowed_beyond_1_12() -> HashSet<&'static str> { "strsplit", "strjoin", "trim", + // TurtleWoW's `Globals.lua:111` table-entry count, which its patched FrameXML calls for + // every list length (Turtle_TransmogUI's available-items/outfits, the guild bank, arena + // rows, binding search). `sizeof` is not 1.12's name and the exception is its `Globals.lua` + // ship — same reason the four above. + "sizeof", // TurtleWoW's addon-message split and delimiters: its `HonorFrame.lua:46` and // `WorldStateFrame.lua:233-335` parse the `TW_HONOR`/`TW_BG` addon payloads with them. "explode",