diff options
| author | the lemons <citrons@mondecitronne.com> | 2022-08-27 01:23:20 -0500 |
|---|---|---|
| committer | the lemons <citrons@mondecitronne.com> | 2022-08-27 01:23:20 -0500 |
| commit | 8bb18a89060ecd581a06238ce3fa5d2170ee3a15 (patch) | |
| tree | 25baba9d2c267b986adfe7af661b3cd99a32b346 /component.lua | |
| parent | 001272dbcbaa1110541e0666af3cea1c97bc199f (diff) | |
implement component system
Diffstat (limited to 'component.lua')
| -rw-r--r-- | component.lua | 24 |
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 |
