Reference › Function reference › Platform

Platform.spells.own

dependency

Call as

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

Record the dependency Platform.spells.own, then call it by that name. A namespaced call does not pass self: use a colon call or pass the object yourself.

What it does

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

Arguments

NameTypeWhat it does
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.

Returns

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

Editions

Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.

It reads no game API directly.

Secret values (Retail and Forever)

On Retail and Forever the game hands addons secret values. This helper checks what it reads (addon.Platform:CanReadValue) and returns nil with a reason such as restricted-value instead of a secret it cannot compare. Treat nil as unavailable, not as false.

How the addon calls it

Dependencies

Source

Platform/spells.lua, line 65. Read only in game; Duplicate makes an editable copy.

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

Back to Function reference