Chame como
Platform.role.readField(self, object, key)
Registre a dependência Platform.role.readField e depois chame-a por esse nome. Uma chamada com namespace não passa self: use uma chamada com dois-pontos ou passe o objeto você mesmo.
O que faz
Reads object[key] in protected mode, used to look up optional APIs. Returns the value (possibly nil), or nil with "restricted-value" when the object or the value is secret, "invalid-api-result" when object is not a table, or "api-error" when indexing raises an error.
Argumentos
| Nome | Tipo | O que faz |
|---|---|---|
self | RMPlatform | Rotation Master platform adapter (normally addon.Platform), used for its CanReadValue check. |
object | table | Table to index; any other type is rejected. |
key | any | Field name to read. |
Retornos
| 1 | any | The field value, possibly nil; nil on failure. |
|---|---|---|
| 2 | string | nil | Reason on failure; nil on success. |
Edições
As funções auxiliares integradas são registradas em todas as edições. O que muda é a API do jogo que elas leem; quando uma está ausente, a função auxiliar recorre a uma alternativa ou retorna nil com um motivo.
Não lê nenhuma API do jogo diretamente.
Valores secretos (Retail e Forever)
No Retail e no Forever, o jogo entrega valores secretos aos addons. Esta função auxiliar verifica o que lê (addon.Platform:CanReadValue) e retorna nil com um motivo como restricted-value em vez de um valor secreto que não consegue comparar. Trate nil como indisponível, não como false.
Como o addon a chama
Platform.role.GetInspectRoleObservationlocal namespace,reason=readField(self,_G,'C_SpecializationInfo')Platform.role.GetTalentGroupRoleObservationlocal query,reason=readField(self,_G,'GetTalentGroupRole')
Código-fonte
Platform/role.lua, linha 19. Somente leitura no jogo; Duplicar cria uma cópia editável.
Platform.role.readField(self, object, key)
if not self:CanReadValue(object) then return nil,'restricted-value' end
if type(object)~='table' then return nil,'invalid-api-result' end
local ok,value=pcall(function() return object[key] end)
if not ok then return nil,'api-error' end
if not self:CanReadValue(value) then return nil,'restricted-value' end
return value