Riferimento › Riferimento delle funzioni › Platform

Platform.spells.copy

dipendenza

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

NomeTipoCosa fa
recordanyNative result table to copy.
fieldstableMap of field name to expected type name.

Valori restituiti

1table | nilNew table holding only the expected, present fields; nil on failure.
2string | nilReason 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

Dipendenze

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

Torna a Riferimento delle funzioni