호출 방법
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), 비교할 수 없는 비공개 값 대신 restricted-value 같은 이유와 함께 nil을 반환합니다. 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