WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   What I'm doing wrong with secureframehandle:GetChildList()? (https://www.wowinterface.com/forums/showthread.php?t=48966)

Duugu 02-21-14 08:47 AM

What I'm doing wrong with secureframehandle:GetChildList()?
 
Ok. Please ignore my post below (can' delete it?). I just realized that tables are restricted and solved my Problem with
kids = table.new(self:GetChildren())

Thanks for peeking in :)

-------------------------------------------------




I currently trying to familiarize myself with the secure frame stuff. (no fun at all ... feels really complicated and undocumented)

My very first steps are this:

Lua Code:
  1. local bar = CreateFrame("Frame", "TestBar", UIParent, "SecureHandlerStateTemplate")
  2. bar:SetPoint("CENTER", UIParent, "CENTER")
  3. bar:SetSize(120, 50)
  4. bar:SetBackdrop({bgFile="Interface\\Tooltips\\UI-Tooltip-Background", edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", tile = false, tileSize = 1, edgeSize = 10, insets = { left = 0, right = 0, top = 0, bottom = 0 }})
  5. bar:SetAttribute('_onstate-stance', [[
  6.     local btn = self:GetFrameRef('TestButton1')
  7.     if btn then
  8.         print(btn:GetName())
  9.     end
  10.     local kids
  11.     self:GetChildList(kids)
  12.     if kids then
  13.         for i, v in ipairs(kids) do
  14.             print(i)
  15.         end
  16.     end
  17.  
  18. ]])
  19. RegisterStateDriver(bar, "stance", "[stance:0] stance0; [stance:1] stance1; [stance:2] stance2; [stance:3] stance3; [stance:4] stance4; [stance:5] stance5;")
  20.  
  21.    
  22. local TestButton1 = CreateFrame("CheckButton", "TestButton1", bar, "SecureHandlerClickTemplate, ActionButtonTemplate")
  23. TestButton1:SetPoint("LEFT", bar, "LEFT")
  24. TestButton1:SetSize(40, 40)
  25. TestButton1:EnableMouse(true)
  26. TestButton1:RegisterForClicks("AnyUp")
  27. TestButton1:SetAttribute("_onclick", [[
  28.     print(self:GetParent():GetName())
  29. ]])
  30.  
  31. local TestButton2 = CreateFrame("CheckButton", "TestButton2", bar, "SecureHandlerClickTemplate, ActionButtonTemplate")
  32. TestButton2:SetPoint("LEFT", bar, "LEFT", 50, 0)
  33. TestButton1:SetSize(40, 40)
  34. TestButton2:EnableMouse(true)
  35. TestButton2:RegisterForClicks("AnyUp")
  36. TestButton2:SetAttribute("_onclick", [[
  37.     print(self:GetParent():GetName())
  38. ]])
  39.        
  40. bar:SetFrameRef("TestButton1", TestButton1)
  41. bar:SetFrameRef("TestButton2", TestButton2)

This code fails on GetChildList with

Code:

14x FrameXML\RestrictedExecution.lua:397: Call failed: FrameXML\RestrictedFrames.lua:197: attempt to get length of local "result" (a nil value)
<in C code>
FrameXML\RestrictedExecution.lua:397: in function <FrameXML\RestrictedExecution.lua:390>
(tail call): ?
(tail call): ?
FrameXML\SecureHandlers.lua:113: in function <FrameXML\SecureHandlers.lua:108>
<in C code>
FrameXML\SecureStateDriver.lua:114: in function <FrameXML\SecureStateDriver.lua:95>
FrameXML\SecureStateDriver.lua:164: in function <FrameXML\SecureStateDriver.lua:146>
<in C code>
FrameXML\SecureStateDriver.lua:11: in function <FrameXML\SecureStateDriver.lua:8>
(tail call): ?
BAB-0.0.1\Core.lua:1501: in main chunk

Locals:
workingEnv = <userdata>
ctrlHandle = <userdata>
pcallFlag = false
LOCAL_Function_Environment_Manager = <function> defined @Interface\FrameXML\RestrictedExecution.lua:209
error = <function> defined =[C]:-1
tostring = <function> defined =[C]:-1

As this is my very first try to do something with the complex secure handler thingi I have no idea what's wrong.

I took GetChildList() from Iriel’s Field Guide to Secure Handlers which states:
<...>Handles can be obtained for other frames as well through the following mechanisms:
• Via the return values from the handle:GetParent(), handle:GetChildren(), and handle:GetChildList(tbl) methods.<...>


Could anyone please show me what I'm doing wrong? I'm lost.

Dridzt 02-21-14 09:18 AM

There is table.new() in WoW Lua 5.1? (did they move to LuaJIT) :confused:

Duugu 02-21-14 09:45 AM

Within a restricted environment, yes. Not in the global environment.
The sandbox doesn't allow the manual creation of tables.

The explanation in Iriel's guide is:
Because tables are stored by reference if normal tables were allowed in the sandbox it could be possible for those table references to leak out, and then be modified by insecure code during execution.

Which makes perfectly sense. :)


All times are GMT -6. The time now is 12:36 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI