Chiamala come
Platform.spells.copy(record, fields)
Registra la dipendenza Platform.spells.copy, poi chiamala con quel nome. Una chiamata con spazio dei nomi non passa self: usa una chiamata con i due punti o passa tu l'oggetto.
Cosa fa
Copies the expected fields of a native result table into a new table, checking each type. fields maps a key to its Lua type name ("icon" accepts a number or a string). Returns the copy with absent fields omitted, or nil with "restricted-value" when the record or a field is secret, or "invalid-api-result" when record is not a table, a field has the wrong type or a number is NaN or infinite.
Argomenti
| Nome | Tipo | Cosa fa |
|---|---|---|
record | any | Native result table to copy. |
fields | table | Map of field name to expected type name. |
Valori restituiti
| 1 | table | nil | New table holding only the expected, present fields; nil on failure. |
|---|---|---|
| 2 | string | nil | Reason on failure. |
Edizioni
Le funzioni di supporto integrate sono registrate su ogni edizione. Ciò che cambia è l'API di gioco che leggono; dove ne manca una, la funzione di supporto ripiega su un'alternativa o restituisce nil con un motivo.
Non legge direttamente alcuna API di gioco.
Valori segreti (Retail e Forever)
Su Retail e Forever il gioco fornisce agli addon valori segreti. Questa funzione di supporto controlla ciò che legge (addon.Platform:CanReadValue) e restituisce nil con un motivo come restricted-value invece di un valore segreto che non può confrontare. Considera nil come non disponibile, non come false.
Come la chiama l'addon
Platform.spells.ownif not built then return copy(record, fields) end
Dipendenze
platform(builtin:Platform/spells.lua:platform)
Sorgente
Platform/spells.lua, riga 35. Nel gioco è in sola lettura; Duplica crea una copia modificabile.
Platform.spells.copy(record, fields)
if not platform:CanReadValue(record) then return nil, "restricted-value" end
if type(record) ~= "table" then return nil, "invalid-api-result" end
local result = {}
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
result[key] = value
end
end
return result