Created
December 18, 2012 07:18
-
-
Save prafulliu/4325774 to your computer and use it in GitHub Desktop.
A window demo in lua. __index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Window = {} -- create a namespace | |
-- create the prototype with default values | |
Window.prototype = {x=0, y=0, width=100, height=100} | |
Window.mt = {} --create a metatable | |
--declare the constructor function | |
function Window.new( o ) | |
setmetatable(o, Window.mt) | |
return o | |
end | |
Window.mt.__index = function ( table, key ) | |
return Window.prototype[key] | |
end | |
w = Window.new{x=10, y=20} | |
print(w.width) | |
print(w.x) | |
print(w["x"]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment