mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-04 05:13:55 -04:00
Added named systems
This commit is contained in:
parent
038111d558
commit
d4efca976c
10 changed files with 176 additions and 92 deletions
29
src/components.lua
Normal file
29
src/components.lua
Normal 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
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue