summaryrefslogtreecommitdiff
path: root/component.lua
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-08-27 01:23:20 -0500
committerthe lemons <citrons@mondecitronne.com>2022-08-27 01:23:20 -0500
commit8bb18a89060ecd581a06238ce3fa5d2170ee3a15 (patch)
tree25baba9d2c267b986adfe7af661b3cd99a32b346 /component.lua
parent001272dbcbaa1110541e0666af3cea1c97bc199f (diff)
implement component system
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