diff --git a/README.md b/README.md index 32182d0f..f3ed4203 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ In the Frame rows, a name that starts with `:` is a method of the widget that th | [Loot](docs/API.md#loot) | `C_Loot.GetNearbyLootableUnits`, `C_Loot.GetLastScanResults`, `C_Loot.IsScanInProgress`, `C_Loot.LootAllCorpses`, `C_Loot.LootUnit`, `C_Loot.LootUnitItem`, `C_Loot.ScanNearbyLoot` | | [LootHistory](docs/API.md#loothistory) | `C_LootHistory.GetNumItems`, `C_LootHistory.GetItem`, `C_LootHistory.GetPlayerInfo`, `C_LootHistory.Clear` | | [LossOfControl](docs/API.md#lossofcontrol) | `C_LossOfControl.GetActiveLossOfControlData`, `C_LossOfControl.GetActiveLossOfControlDataCount`, `C_LossOfControl.GetSchoolLockout` | -| [Lua](docs/API.md#lua) | `collectgarbage` (5.1 options), `coroutine.create`, `coroutine.resume`, `coroutine.running`, `coroutine.status`, `coroutine.wrap`, `coroutine.yield`, `CreateFromMixins`, `math.fmod`, `math.huge`, `math.modf`, `Mixin`, `select`, `strcmputf8i`, `strconcat`, `string.concat`, `string.gmatch`, `string.gsub` (table replacement), `string.join`, `string.match`, `string.reverse`, `string.split`, `string.trim`, `strjoin`, `strlenutf8`, `strmatch`, `strreplace`, `strrev`, `strsplit`, `strsplittable`, `strtrim`, `table.count`, `table.maxn`, `table.wipe`, `unpack` (range args), `xpcall` (argument forwarding) | +| [Lua](docs/API.md#lua) | `collectgarbage` (5.1 options), `coroutine.create`, `coroutine.resume`, `coroutine.running`, `coroutine.status`, `coroutine.wrap`, `coroutine.yield`, `CreateFromMixins`, `math.fmod`, `math.huge`, `math.modf`, `Mixin`, `select`, `strcmputf8i`, `strconcat`, `string.concat`, `string.gmatch`, `string.gsub` (table replacement), `string.join`, `string.match`, `string.reverse`, `string.split`, `string.trim`, `strjoin`, `strlenutf8`, `strmatch`, `strreplace`, `strrev`, `strsplit`, `strsplittable`, `strtrim`, `table.count`, `table.maxn`, `table.wipe`, `unpack` (range args), `wipe`, `xpcall` (argument forwarding) | | [Macros](docs/API.md#macros) | `C_Macro.CreateMacro`, `C_Macro.EditMacro`, `C_Macro.SetMacroDisplay`, `DeleteMacro` / `EditMacro` / `GetMacroInfo` / `PickupMacro` by name, `GetLooseMacroIcons`, `GetLooseMacroItemIcons`, `GetMacroBody`, `GetMacroIcons`, `GetMacroItem`, `GetMacroItemIcons`, `GetMacroSpell`, `GetRunningMacro`, `GetRunningMacroButton`, `RunMacroText`, `SetMacroItem`, `SetMacroSpell`, `StopMacro` | | [Mail](docs/API.md#mail) | `GetInboxItemLink`, `GetSendMailItemLink` | | [Map](docs/API.md#map) | `C_Map.CanSetUserWaypointOnMap`, `C_Map.ClearUserWaypoint`, `C_Map.GetAreaInfo`, `C_Map.GetAreas`, `C_Map.GetAreaTriggerInfo`, `C_Map.GetAreaTriggers`, `C_Map.GetBestMapForUnit`, `C_Map.GetFallbackWorldMapID`, `C_Map.GetMapAreaIDs`, `C_Map.GetMapArtLayers`, `C_Map.GetMapArtLayerTextures`, `C_Map.GetMapChildrenInfo`, `C_Map.GetMapInfo`, `C_Map.GetMapInfoAtPosition`, `C_Map.GetMapOverlays`, `C_Map.GetMapPosFromWorldPos`, `C_Map.GetMapRectOnMap`, `C_Map.GetMapWorldSize`, `C_Map.GetPlayerMapPosition`, `C_Map.GetUserWaypoint`, `C_Map.GetUserWaypointFromHyperlink`, `C_Map.GetUserWaypointHyperlink`, `C_Map.GetUserWaypointPositionForMap`, `C_Map.GetWorldPosFromMapPos`, `C_Map.HasUserWaypoint`, `C_Map.MapHasArt`, `C_Map.SetUserWaypoint` | diff --git a/docs/API.md b/docs/API.md index 0dfc8ac7..c994daa0 100644 --- a/docs/API.md +++ b/docs/API.md @@ -643,7 +643,7 @@ build instructions. - [`unpack(list [, i [, j]])`](#unpacklist--i--j) - [`xpcall(f, msgh [, arg1, ...])`](#xpcallf-msgh--arg1-) - [`collectgarbage(opt [, arg])`](#collectgarbageopt--arg) - - [`table.wipe(t)`](#tablewipet) + - [`table.wipe(t)` / `wipe(t)`](#tablewipet--wipet) - [`table.count(tbl)`](#tablecounttbl) - [`table.maxn(t)`](#tablemaxnt) - [Stale table lengths (5.1 healing)](#stale-table-lengths-51-healing) @@ -15057,10 +15057,11 @@ optional numeric threshold and errored on every string option - A number (or no argument) keeps the stock threshold behavior unchanged. -### `table.wipe(t)` +### `table.wipe(t)` / `wipe(t)` Removes every key from `t`, leaving it empty but preserving its -internal hash and array capacity. Returns `t` for chaining. +internal hash and array capacity. Returns `t` for chaining. `wipe` is +the same function as a global. ```lua local cache = {} diff --git a/src/HookSecureFunc.cpp b/src/HookSecureFunc.cpp index ac80feac..d9831aeb 100644 --- a/src/HookSecureFunc.cpp +++ b/src/HookSecureFunc.cpp @@ -32,9 +32,8 @@ namespace { // that are not base-library functions at all. So do not derive this from // the engine's `luaopen_base` table (`0x00811E28`, 36 entries — see // BlizzardScriptAPI.md §3); that is a different set with a different -// purpose. Names with no 1.12 counterpart (`wipe` is `table.wipe` here; the -// secure family does not exist) stay for parity of the error an addon -// sees. Sorted alphabetically. +// purpose. Names with no 1.12 counterpart (the secure family does not +// exist) stay for parity of the error an addon sees. Sorted alphabetically. const char *const kUnhookableNames[] = { "getfenv", "getmetatable", "hooksecurefunc", "ipairs", "issecurevalue", "issecurevariable", "next", "pairs", "pcall", "pcallwithenv", "rawget", diff --git a/src/embed/AddOns/!!!ClassicAPI/Util/CallbackRegistry.lua b/src/embed/AddOns/!!!ClassicAPI/Util/CallbackRegistry.lua index 38f63c1f..f964bd79 100644 --- a/src/embed/AddOns/!!!ClassicAPI/Util/CallbackRegistry.lua +++ b/src/embed/AddOns/!!!ClassicAPI/Util/CallbackRegistry.lua @@ -10,7 +10,6 @@ -- (an error goes to the error handler and the other callbacks still run), -- but every call to a vararg function builds an `arg` table in Lua 5.0, -- which would cost a table per callback per event. --- - 1.12 has no global wipe, so UnregisterEvents uses table.wipe. local secureexecuterange = secureexecuterange; local securecallfunction = securecallfunction; @@ -19,7 +18,6 @@ local error = error; local pairs = pairs; local rawset = rawset; local next = next; -local wipe = table.wipe; local GetOrCreateTableEntry = GetOrCreateTableEntry; local CallbackType = EnumUtil.MakeEnum("Closure", "Function"); diff --git a/src/embed/AddOns/!!!ClassicAPI/Util/MixinUtil.lua b/src/embed/AddOns/!!!ClassicAPI/Util/MixinUtil.lua index 8b070351..8cfb6037 100644 --- a/src/embed/AddOns/!!!ClassicAPI/Util/MixinUtil.lua +++ b/src/embed/AddOns/!!!ClassicAPI/Util/MixinUtil.lua @@ -1,9 +1,4 @@ -- Backport of retail's Blizzard_SharedXML/MixinUtil.lua. --- --- Implementation differences from the retail source: --- - wipe is table.wipe here. - -local wipe = table.wipe; -- The following function is used with permission from Daniel Stephens -- texture - Texture diff --git a/src/embed/AddOns/!!!ClassicAPI/Util/SecureTypes.lua b/src/embed/AddOns/!!!ClassicAPI/Util/SecureTypes.lua index c30749ea..c398cf93 100644 --- a/src/embed/AddOns/!!!ClassicAPI/Util/SecureTypes.lua +++ b/src/embed/AddOns/!!!ClassicAPI/Util/SecureTypes.lua @@ -4,7 +4,6 @@ -- - 1.12 has no secret values, so the issecretvalue asserts are dropped. -- - Lua 5.0 has no `...` as an expression and no `#` operator; varargs -- forward through unpack(arg) and lengths come from table.getn. --- - wipe is table.wipe here. local assert = assert; local ContainsIf = ContainsIf; @@ -23,7 +22,7 @@ local tCount = table.count; local tDeleteItem = tDeleteItem; local tinsert = table.insert; local tremove = table.remove; -local wipe = table.wipe; +local wipe = wipe; -- Secure types are expected to be used by Blizzard code to prevent taint propagation -- while accessing values, particularly in cases where container types are used that can have diff --git a/src/table/Wipe.cpp b/src/table/Wipe.cpp index 688e1b25..fffdd437 100644 --- a/src/table/Wipe.cpp +++ b/src/table/Wipe.cpp @@ -72,8 +72,23 @@ static int __fastcall Script_table_wipe(void *L) { return 1; } +// --- Documentation ---------------------------------------------------------- + +const Game::Doc::Field kWipeArgs[] = { + Game::Doc::Req("tbl", "table"), +}; +const Game::Doc::Field kWipeRets[] = { + Game::Doc::Req("tbl", "table", "The same table, now empty."), +}; +const Game::Doc::Function kWipe{"Removes every key from a table.", kWipeArgs, kWipeRets, + "LuaGlobals"}; + +// `wipe` is the global alias 3.3.5's FrameScript compat preamble sets next +// to `tinsert` / `tremove` (`wipe = tab.wipe`). 1.12's preamble predates +// table.wipe, so the alias is registered here; retail FrameXML calls it. static void RegisterLuaFunctions() { Game::Lua::RegisterTableFunction("table", "wipe", &Script_table_wipe); + Game::Lua::RegisterGlobalFunction("wipe", &Script_table_wipe, &kWipe); } static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};