Riferimento › Riferimento delle funzioni › Platform

Platform.spells.own

dipendenza

Chiamala come

Platform.spells.own(record, fields, built)

Registra la dipendenza Platform.spells.own, 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

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".

Argomenti

NomeTipoCosa fa
recordanyNative result table, or a table the caller built from a legacy multi-value return.
fieldstableMap of field name to expected type name.
builtboolean | nilTrue when the caller built record itself, so it may be modified in place.

Valori restituiti

1table | nilRecord holding only the expected 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 65. Nel gioco è in sola lettura; Duplica crea una copia modificabile.

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

Torna a Riferimento delle funzioni