平民程序 - linghuye's blog

天下风云出我辈,一入江湖岁月催。皇图霸业谈笑中,不胜人生一场醉。提剑跨骑挥鬼雨,白骨如山鸟惊飞。尘事如潮人如水,只笑江湖几人回。

随笔 - 221, 文章 - 0, 评论 - 680, 引用 - 0
数据加载中……

WoW的UI脚本对象实现方法

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.

posted on 2008-04-02 22:27 linghuye 阅读(2005) 评论(0)  编辑 收藏 引用 所属分类: 编程札记

只有注册用户登录后才能发表评论。