Appel
Platform.spells.own(record, fields, built)
Enregistrez la dépendance Platform.spells.own, puis appelez-la sous ce nom. Un appel par espace de noms ne transmet pas self : utilisez un appel avec deux-points ou passez l'objet vous-même.
Ce qu'elle fait
Returns a record holding only the expected fields, each checked by type. A record it did not build itself, a table with a metatable or a non-table goes through copy; a plain table the caller built is checked and stripped of unexpected keys in place. Fails like copy, with "restricted-value" or "invalid-api-result".
Arguments
| Nom | Type | Ce qu'elle fait |
|---|---|---|
record | any | Native result table, or a table the caller built from a legacy multi-value return. |
fields | table | Map of field name to expected type name. |
built | boolean | nil | True when the caller built record itself, so it may be modified in place. |
Retours
| 1 | table | nil | Record holding only the expected fields; nil on failure. |
|---|---|---|
| 2 | string | nil | Reason on failure. |
Éditions
Les fonctions utilitaires intégrées sont enregistrées sur toutes les éditions. Ce qui diffère, c'est l'API du jeu qu'elles lisent ; quand l'une manque, la fonction utilitaire se rabat sur une alternative ou renvoie nil avec une raison.
Elle ne lit directement aucune API du jeu.
Valeurs secrètes (Retail et Forever)
Sur Retail et Forever, le jeu transmet aux addons des valeurs secrètes. Cette fonction utilitaire vérifie ce qu'elle lit (addon.Platform:CanReadValue) et renvoie nil avec une raison telle que restricted-value au lieu d'une valeur secrète qu'elle ne peut pas comparer. Traitez nil comme indisponible, pas comme false.
Comment l'addon l'appelle
Platform.spells.GetSpellChargeslocal charges,why=own(record,chargeFields,built)Platform.spells.GetSpellCooldownlocal cooldown, why = own(record, cooldownFields, built)
Dépendances
copy→Platform.spells.copyplatform(builtin:Platform/spells.lua:platform)
Source
Platform/spells.lua, ligne 65. En lecture seule dans le jeu ; Dupliquer crée une copie modifiable.
Platform.spells.own(record, fields, built)
if not built then return copy(record, fields) end
if not platform:CanReadValue(record) then return nil, "restricted-value" end
if type(record) ~= "table" or getmetatable(record) ~= nil then return copy(record, fields) end
for key, kind in pairs(fields) do
local value = record[key]
if not platform:CanReadValue(value) then return nil, "restricted-value" end
if value ~= nil then
if type(value) ~= kind and not (kind == "icon" and (type(value) == "number" or type(value) == "string")) then
return nil, "invalid-api-result"
end
if type(value) == "number" and (value ~= value or value == math.huge or value == -math.huge) then
return nil, "invalid-api-result"
end
end
end
local key = next(record)
while key ~= nil do
local following = next(record, key)
if fields[key] == nil then record[key] = nil end
key = following
end
return record