__index

Window = {}
Window.prototype = {x = 0, y = 0, width = 70, height = 100}
Window.mt = {}

function Window.new(o)
    setmetatable(o, Window.mt)
    return o
end

--[[Window.mt.__index = function (table, key)
    return Window.prototype[key]
end--]]

Window.mt.__index = Window.prototype--当我们想不通过调用__index metamethod来访问一个表,我们可以使用rawget函数,

w = Window.new{x = 10, y = 20}
print(w.width)

 

posted @ 2016-09-24 22:06  zzyoucan  阅读(125)  评论(0编辑  收藏  举报