Llamar como
Platform.spells.own(record, fields, built)
Registra la dependencia Platform.spells.own y luego llámala con ese nombre. Una llamada con espacio de nombres no pasa self: usa una llamada con dos puntos o pasa tú mismo el objeto.
Qué hace
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
| Nombre | Tipo | Qué hace |
|---|---|---|
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. |
Ediciones
Las funciones auxiliares integradas se registran en todas las ediciones. Lo que cambia es la API del juego que leen; donde falta alguna, la función auxiliar recurre a una alternativa o devuelve nil con un motivo.
No lee directamente ninguna API del juego.
Valores secretos (Retail y Forever)
En Retail y Forever, el juego entrega a los addons valores secretos. Esta función auxiliar comprueba lo que lee (addon.Platform:CanReadValue) y, en lugar de un secreto que no puede comparar, devuelve nil con un motivo como restricted-value. Trata nil como no disponible, no como falso.
Cómo la llama el addon
Platform.spells.GetSpellChargeslocal charges,why=own(record,chargeFields,built)Platform.spells.GetSpellCooldownlocal cooldown, why = own(record, cooldownFields, built)
Dependencias
copy→Platform.spells.copyplatform(builtin:Platform/spells.lua:platform)
Código fuente
Platform/spells.lua, línea 65. Solo lectura en el juego; Duplicar crea una copia editable.
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