Reference › Function reference › Platform

Platform.spells.copy

dependency

Call as

Platform.spells.copy(record, fields)

Record the dependency Platform.spells.copy, 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

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.

Arguments

NameTypeWhat it does
recordanyNative result table to copy.
fieldstableMap of field name to expected type name.

Returns

1table | nilNew table holding only the expected, present 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 35. Read only in game; Duplicate makes an editable copy.

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

Back to Function reference