Created
April 3, 2015 16:52
-
-
Save ndbeals/f681c40daa3de74db820 to your computer and use it in GitHub Desktop.
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
function Class( base ) | |
local class = { -- a new class metatable | |
base = base | |
} | |
class.__index = class | |
local classmt = { -- the new classes' meta table, this allows inheritence if the class has a base, and lets you create a new instance with <classname>() | |
__index = base | |
} | |
classmt.__call = function( class , ... ) -- expose a constructor which can be called by <classname>(<args>) | |
local obj = {} -- new instance of the class to be manipulated. | |
setmetatable( obj , class ) | |
if class.Initialize then | |
class.Initialize( obj , ... ) | |
end | |
return obj | |
end | |
setmetatable(class, classmt) | |
return class | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment