Module:Class

From Halo Esports Wiki
Jump to: navigation, search

Documentation for this module may be created at Module:Class/doc

local p = {}

function p.Class(baseClass)
	local class = {}
	local obj_mt = {
		__index = class
	}
	local class_mt = {
		__call = function(t, ...)
			local obj = setmetatable({}, obj_mt)
			if obj.new then
				obj:new(...)
			end
			return obj
		end
	}
	if baseClass ~= nil then
		class_mt.__index = baseClass
		function class:super(...)
			return baseClass.new(self, ...)
		end
	end
	setmetatable(class, class_mt)
	return class
end

return p