Chame como
Platform.spells.own(record, fields, built)
Registre a dependência Platform.spells.own e depois chame-a por esse nome. Uma chamada com namespace não passa self: use uma chamada com dois-pontos ou passe o objeto você mesmo.
O que faz
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".
Argumentos
| Nome | Tipo | O que faz |
|---|---|---|
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. |
Retornos
| 1 | table | nil | Record holding only the expected fields; nil on failure. |
|---|---|---|
| 2 | string | nil | Reason on failure. |
Edições
As funções auxiliares integradas são registradas em todas as edições. O que muda é a API do jogo que elas leem; quando uma está ausente, a função auxiliar recorre a uma alternativa ou retorna nil com um motivo.
Não lê nenhuma API do jogo diretamente.
Valores secretos (Retail e Forever)
No Retail e no Forever, o jogo entrega valores secretos aos addons. Esta função auxiliar verifica o que lê (addon.Platform:CanReadValue) e retorna nil com um motivo como restricted-value em vez de um valor secreto que não consegue comparar. Trate nil como indisponível, não como false.
Como o addon a chama
Platform.spells.GetSpellChargeslocal charges,why=own(record,chargeFields,built)Platform.spells.GetSpellCooldownlocal cooldown, why = own(record, cooldownFields, built)
Dependências
copy→Platform.spells.copyplatform(builtin:Platform/spells.lua:platform)
Código-fonte
Platform/spells.lua, linha 65. Somente leitura no jogo; Duplicar cria uma cópia editável.
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