WoW的UI/XML脚本中定义的每个UI对象都可以在lua脚本中使用其名字进行调用,如
GameMenuFrame:Show(); // 方法
local a = checkbutton.isChecked;// 属性
在wow中测试了下,发现:
1.type(GameMenuFrame) == "table"
2.GameMenuFrame has only one field, that is, GameMenuFrame[0] is a userdata
3.GameMenuFrame has metatable, GameMenuFrame[0] has NO metatable.
4.The metatable of GameMenuFrame has only one override field, that is "__index".
5.And that "__index" field is a table contains functions.
So when calling GameMenuFrame:Show(), it calls GameMenuFrame.Show(GameMenuFrame), the GameMenuFrame has not a "Show" field, so it will find it in its metatable's "__index" field, that is:
getmetable(GameMenuFrame)["__index"]["Show"] which refers to a embbed function, the implementation will get the userdata from the GameMenuFrame table. This userdata points to a C memory, or C++ object, or C++ Object pointer, or anything.
For the attribute like 'checkbutton.tooltipText', the tooltipText field is a complete lua variable, created by wow lua script. C/C++ implemetation needs some trouble to read it into binary code and then use it.