Skip to content

Instantly share code, notes, and snippets.

@prafulliu
Created December 18, 2012 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prafulliu/4325774 to your computer and use it in GitHub Desktop.
Save prafulliu/4325774 to your computer and use it in GitHub Desktop.
A window demo in lua. __index
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