Справочник › Справочник функций › Platform

Platform.spells.own

зависимость

Как вызывать

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

Запишите зависимость Platform.spells.own и вызывайте её по этому имени. Вызов через пространство имён не передаёт self: используйте вызов через двоеточие или передайте объект сами.

Что делает

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

Аргументы

ИмяТипЧто делает
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.

Возвращает

1table | nilRecord holding only the expected fields; nil on failure.
2string | nilReason on failure.

Издания

Встроенные помощники регистрируются во всех изданиях. Различается игровой API, который они читают; если нужного API нет, помощник использует запасной вариант или возвращает nil с причиной.

Не читает игровой API напрямую.

Секретные значения (Retail и Forever)

В Retail и Forever игра передаёт аддонам секретные значения. Этот помощник проверяет то, что читает (addon.Platform:CanReadValue), и вместо секретного значения, которое нельзя сравнить, возвращает nil с причиной, например restricted-value. Считайте nil недоступным значением, а не ложью.

Как его вызывает аддон

Зависимости

Исходный код

Platform/spells.lua, строка 65. В игре только для чтения; «Дублировать» создаёт редактируемую копию.

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

Назад: Справочник функций