summaryrefslogtreecommitdiff
path: root/component.lua
diff options
context:
space:
mode:
Diffstat (limited to 'component.lua')
-rw-r--r--component.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/component.lua b/component.lua
new file mode 100644
index 0000000..c1c16d8
--- /dev/null
+++ b/component.lua
@@ -0,0 +1,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