Created
October 17, 2016 04:41
-
-
Save marcoonroad/621c1f796eac120a00b3d5248dc47478 to your computer and use it in GitHub Desktop.
Example for this post: http://marcoonroad.github.io/Kinds-of-Delegation
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
local prototype = require 'prototype' | |
local point = prototype: clone { x = 0, y = 0, } | |
function point: move (x, y) | |
self.x = self.x + x | |
self.y = self.y + y | |
end | |
function point: pretty ( ) | |
local format = "(%d, %d)" | |
return format: format (self.x, self.y) | |
end | |
local printable = { } | |
function printable: print ( ) | |
print (self: pretty ( )) | |
end | |
local instance = point: clone { protected = false, } | |
local extension = instance: extend (printable) | |
extension: print ( ) | |
extension: move (5, 15) | |
extension: print ( ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment