Added named systems

This commit is contained in:
Tjakka5 2019-12-19 10:34:02 +01:00
parent 038111d558
commit d4efca976c
10 changed files with 176 additions and 92 deletions

29
src/components.lua Normal file
View file

@ -0,0 +1,29 @@
-- Components
local PATH = (...):gsub('%.[^%.]+$', '')
local Type = require(PATH..".type")
local Components = {}
function Components.register(name, component)
if (type(name) ~= "string") then
error("bad argument #1 to 'Components.register' (string expected, got "..type(name)..")", 3)
end
if (not Type.isComponent(component)) then
error("bad argument #2 to 'Components.register' (component expected, got "..type(component)..")", 3)
end
if (rawget(Components, name)) then
error("bad argument #2 to 'Components.register' (Component with name '"..name.."' is already registerd)", 3)
end
Components[name] = component
end
return setmetatable(Components, {
__index = function(_, name)
error("Attempt to index component '"..tostring(name).."' that does not exist / was not registered", 2)
end
})