Appel
Platform.spells.copy(record, fields)
Enregistrez la dépendance Platform.spells.copy, puis appelez-la sous ce nom. Un appel par espace de noms ne transmet pas self : utilisez un appel avec deux-points ou passez l'objet vous-même.
Ce qu'elle fait
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
| Nom | Type | Ce qu'elle fait |
|---|---|---|
record | any | Native result table to copy. |
fields | table | Map of field name to expected type name. |
Retours
| 1 | table | nil | New table holding only the expected, present fields; nil on failure. |
|---|---|---|
| 2 | string | nil | Reason on failure. |
Éditions
Les fonctions utilitaires intégrées sont enregistrées sur toutes les éditions. Ce qui diffère, c'est l'API du jeu qu'elles lisent ; quand l'une manque, la fonction utilitaire se rabat sur une alternative ou renvoie nil avec une raison.
Elle ne lit directement aucune API du jeu.
Valeurs secrètes (Retail et Forever)
Sur Retail et Forever, le jeu transmet aux addons des valeurs secrètes. Cette fonction utilitaire vérifie ce qu'elle lit (addon.Platform:CanReadValue) et renvoie nil avec une raison telle que restricted-value au lieu d'une valeur secrète qu'elle ne peut pas comparer. Traitez nil comme indisponible, pas comme false.
Comment l'addon l'appelle
Platform.spells.ownif not built then return copy(record, fields) end
Dépendances
platform(builtin:Platform/spells.lua:platform)
Source
Platform/spells.lua, ligne 35. En lecture seule dans le jeu ; Dupliquer crée une copie modifiable.
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