summaryrefslogtreecommitdiff
path: root/component.lua
blob: c1c16d878b1ee85750c4f97a6eca873fd1545f59 (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
local mt = {}
function mt:__call(instance)
	instance = instance or {}
	assert(type(instance) == 'table')
	local ci = setmetatable({i = instance, inited = false, obj = false},
		{__index = self, __newindex = function()assert(false)end})
	return ci
end

-- create a new component type. the arguments are interpreted as a list of
-- dependences. each dependency is expressed as an array. the first value is
-- the component type. the optional second value is the default properties
local function component(...)
	local c = {}
	c.component_type = c
	c.deps = {...}
	for i, dep in ipairs(c.deps) do
		assert(#dep ~= 0)
	end
	c.init = function() end
	return setmetatable(c, mt)
end

return component