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)
时间: 2024-11-07 21:21:59