summaryrefslogtreecommitdiff
path: root/class.lua
blob: c9fb87bc572287e6bac3a9a8d9245120ef8d6a8c (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
31
32
33
34
35
36
37
38
-- minimal class library
--
-- 	local Foo = class()
-- 	function Foo.make(cls, x,y,z)
-- 		return setmetatable({x=x,y=y,z=z},cls)
-- 	end
-- 	function Foo.whatever(self, ...)
-- 		...
-- 	end
-- 	...
-- 	local foo = Foo:make(...)
-- 	foo:whatever(...)


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})