Skip to content

@rwaldron /Pattern.lua forked from creationix/Pattern.lua
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Pattern.js ported to Lua
Pattern = {}
function Pattern:extend(obj)
local child = obj or {}
setmetatable(child, {__index = self})
return child
end
function Pattern:new(...)
local obj = {}
setmetatable(obj, {__index = self})
if not self.initialize then
return obj
end
obj:initialize(unpack({...}))
return obj
end
Rectangle = Pattern:extend()
function Rectangle:initialize(width, height)
self.width = width
self.height = height
end
function Rectangle:getArea()
return self.width * self.height
end
local rect = Rectangle:new(10, 20)
print("rect " .. tostring(rect))
print("rect:getArea() " .. rect:getArea())
local MagicRectangle = Rectangle:extend()
function MagicRectangle:getArea()
return self.width * self.height * 100
end
local rect2 = MagicRectangle:new(10, 20)
print("rect2 " .. tostring(rect2))
print("rect2:getArea() " .. rect2:getArea())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.