Aufruf als
Platform.spells.copy(record, fields)
Erfassen Sie die Abhängigkeit Platform.spells.copy und rufen Sie sie dann unter diesem Namen auf. Ein Aufruf über den Namensraum übergibt kein self: Verwenden Sie einen Doppelpunkt-Aufruf oder übergeben Sie das Objekt selbst.
Was sie bewirkt
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.
Argumente
| Name | Typ | Was sie bewirkt |
|---|---|---|
record | any | Native result table to copy. |
fields | table | Map of field name to expected type name. |
Rückgabewerte
| 1 | table | nil | New table holding only the expected, present fields; nil on failure. |
|---|---|---|
| 2 | string | nil | Reason on failure. |
Editionen
Integrierte Hilfsfunktionen werden auf jeder Edition registriert. Unterschiedlich ist die Spiel-API, die sie lesen; fehlt eine, weicht die Hilfsfunktion aus oder gibt nil mit einem Grund zurück.
Sie liest keine Spiel-API direkt.
Geheime Werte (Retail und Forever)
Auf Retail und Forever übergibt das Spiel Addons geheime Werte. Diese Hilfsfunktion prüft, was sie liest (addon.Platform:CanReadValue), und gibt statt eines geheimen Werts, den sie nicht vergleichen kann, nil mit einem Grund wie restricted-value zurück. Behandeln Sie nil als nicht verfügbar, nicht als false.
Wie das Addon sie aufruft
Platform.spells.ownif not built then return copy(record, fields) end
Abhängigkeiten
platform(builtin:Platform/spells.lua:platform)
Quelle
Platform/spells.lua, Zeile 35. Im Spiel schreibgeschützt; Duplizieren erstellt eine bearbeitbare Kopie.
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