SecureHandlerAttributeTemplate is one of the SecureHandler templates introduced in Patch 3.0. Those templates exist in order to allow addon code to execute within a restricted environment, where it may perform protected actions but has access only to a limited subset of the API. SecureHandlerAttributeTemplate executes snippets whenever an attribute on the frame (whose name does not begin with "_") changes value.
Snippets[]
The handler executes the following snippets in a restricted environment:
- _onattributechanged (self, name, value)
- The snippet is executed when the an attribute changes value; unless its name begins with an underscore.
- self
- Secure frame handle to the frame.
- name
- String - attribute name.
- value
- Mixed - new attribute value. Note that if the value is not a string, boolean or a number, it'll be replaced with nil -- this a limitation enforced by the restricted environment.
Example[]
Suppose we wanted to respond to :SetFrameRef() invocations on the frame by handling the frame in some fashion.
local frame = CreateFrame("FRAME", "MyAttributeFrame", UIParent, "SecureHandlerAttributeTemplate");
frame:SetAttribute("_onattributechanged", [=[
if name:match("frameref%-.+") then
-- value is nil, since the original type is userdata.
-- We can fix that by asking for the frame ref:
value = self:GetFrameRef(name:match("frameref%-(.+)"));
-- Now handle the name/value pair in some fashion...
print("SetFrameRef: ", name, value);
end
]=]);
frame:SetFrameRef("ref", frame);
| |||||||||||||||||