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/systems.lua Normal file
View file

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