I have a question for @ x-pressive.com
I am wondering what the reason was behind coding the widget creation functions to write, delete data into/from the table we provide as a parameter?
I came across this when I was creating a collection of widgets from a table description.
For example:
--The Table Description for my label
local t = {
textColor = {255,255,255},
fontSize = "64",
parentGroup = "WIN\_SAMPLE",
x = "center",
y = -5,
name = "MyWidget",
theme = "theme\_1",
width = "20%",
caption = "My Label",
textAlign = "left",
icon = nil,
}
--print the table
print("------------------\>Before Create")
for i,v in pairs(t) do
print(i,v)
end
--create a label from my description
local myLabel = \_G.GUI.NewLabel(t)
--Lets see what was added
print("-------------------\>After Create")
for i,v in pairs(t) do
print(i,v)
end
--Delete the widget
myLabel:destroy()
--Where did my data go?
print("----------------\>After Destroy")
for i,v in pairs(t) do
print(i,v)
end
So I looked at the source code and found that it was indeed writing directly into the table that I had provided as a parameter.
[update]
It’s not an issue, just wondering about the style is all.
Since widget candy does not use meta tables, you still load from a table description by doing the following:
t = {}
setmetatable(t, {\_\_index=tableDescription}
local myLabel = \_G.GUI.NewLabel(t)
With this code, the NewLabel method will write into"t" and not into “tableDescription”. Also it will prevent the Widget from deleting key/values from “tableDescription” when you call destroy. “t” gets its values deleted instead.
-Phil
.
[import]uid: 106158 topic_id: 25953 reply_id: 115722[/import]