Referência › Referência de funções › Platform

Platform.spells.copy

dependência

Chame como

Platform.spells.copy(record, fields)

Registre a dependência Platform.spells.copy 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

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.

Argumentos

NomeTipoO que faz
recordanyNative result table to copy.
fieldstableMap of field name to expected type name.

Retornos

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

Dependências

Código-fonte

Platform/spells.lua, linha 35. Somente leitura no jogo; Duplicar cria uma cópia editável.

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

Voltar para Referência de funções