Call as
Platform.role.readField(self, object, key)
Record the dependency Platform.role.readField, then call it by that name. A namespaced call does not pass self: use a colon call or pass the object yourself.
What it does
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.
Arguments
| Name | Type | What it does |
|---|---|---|
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. |
Returns
| 1 | any | The field value, possibly nil; nil on failure. |
|---|---|---|
| 2 | string | nil | Reason on failure; nil on success. |
Editions
Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.
It reads no game API directly.
Secret values (Retail and Forever)
On Retail and Forever the game hands addons secret values. This helper checks what it reads (addon.Platform:CanReadValue) and returns nil with a reason such as restricted-value instead of a secret it cannot compare. Treat nil as unavailable, not as false.
How the addon calls it
Platform.role.GetInspectRoleObservationlocal namespace,reason=readField(self,_G,'C_SpecializationInfo')Platform.role.GetTalentGroupRoleObservationlocal query,reason=readField(self,_G,'GetTalentGroupRole')
Source
Platform/role.lua, line 19. Read only in game; Duplicate makes an editable copy.
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