Skip to content

Instantly share code, notes, and snippets.

@ndbeals
Created April 3, 2015 16:52
Show Gist options
  • Save ndbeals/f681c40daa3de74db820 to your computer and use it in GitHub Desktop.
Save ndbeals/f681c40daa3de74db820 to your computer and use it in GitHub Desktop.
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