summaryrefslogtreecommitdiff
path: root/common/class.lua
blob: f5cd46e12ec331cd52c5a43dcafa2d6e8aebb99f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- currently a class is a table T with T.__index = T
-- then to make an instance of this class, we do setmetatable(instance,T)
-- this should be fine for anything we wish to do. it is possible we will eventually
-- split this into two separate tables though, perhaps? i don't see why we would ever
-- do this though.

local function class()
	local T = {}
	T.__index = T
	return T
end

local function extend(Base)
	local T = {}
	T.__index = T
	for k,v in pairs(Base) do
		if k:sub(1,2) == "__" and k~="__index" then
			T[k]=v
		end
	end
	setmetatable(T,{__index=Base})
	return T
end

return setmetatable({
	class=class,
	extend=extend
},{__call=class})