Как вызывать
Platform.spells.copy(record, fields)
Запишите зависимость Platform.spells.copy и вызывайте её по этому имени. Вызов через пространство имён не передаёт self: используйте вызов через двоеточие или передайте объект сами.
Что делает
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.
Аргументы
| Имя | Тип | Что делает |
|---|---|---|
record | any | Native result table to copy. |
fields | table | Map of field name to expected type name. |
Возвращает
| 1 | table | nil | New table holding only the expected, present fields; nil on failure. |
|---|---|---|
| 2 | string | nil | Reason on failure. |
Издания
Встроенные помощники регистрируются во всех изданиях. Различается игровой API, который они читают; если нужного API нет, помощник использует запасной вариант или возвращает nil с причиной.
Не читает игровой API напрямую.
Секретные значения (Retail и Forever)
В Retail и Forever игра передаёт аддонам секретные значения. Этот помощник проверяет то, что читает (addon.Platform:CanReadValue), и вместо секретного значения, которое нельзя сравнить, возвращает nil с причиной, например restricted-value. Считайте nil недоступным значением, а не ложью.
Как его вызывает аддон
Platform.spells.ownif not built then return copy(record, fields) end
Зависимости
platform(builtin:Platform/spells.lua:platform)
Исходный код
Platform/spells.lua, строка 35. В игре только для чтения; «Дублировать» создаёт редактируемую копию.
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