CONCORD IS DEAD

Long live Concord!!
This commit is contained in:
Pablo Ariel Mayobre 2020-03-14 07:45:25 -03:00
parent 5dffe04b72
commit c640641b09
No known key found for this signature in database
GPG key ID: 5ACD9E6858BEB0A9
16 changed files with 263 additions and 424 deletions

View file

@ -1,6 +1,10 @@
--- A pure data container that is contained by a single entity.
-- @classmod Component
local PATH = (...):gsub('%.[^%.]+$', '')
local Components = require(PATH..".components")
local Component = {}
Component.__mt = {
__index = Component,
@ -9,7 +13,15 @@ Component.__mt = {
--- Creates a new ComponentClass.
-- @tparam function populate Function that populates a Component with values
-- @treturn Component A new ComponentClass
function Component.new(populate)
function Component.new(name, populate)
if (type(name) ~= "string") then
error("bad argument #1 to 'Component.new' (string expected, got "..type(name)..")", 2)
end
if (rawget(Components, name)) then
error("bad argument #1 to 'Component.new' (ComponentClass with name '"..name.."' was already registerd)", 2) -- luacheck: ignore
end
if (type(populate) ~= "function" and type(populate) ~= "nil") then
error("bad argument #1 to 'Component.new' (function/nil expected, got "..type(populate)..")", 2)
end
@ -17,7 +29,7 @@ function Component.new(populate)
local componentClass = setmetatable({
__populate = populate,
__name = nil,
__name = name,
__isComponentClass = true,
}, Component.__mt)
@ -25,6 +37,8 @@ function Component.new(populate)
__index = componentClass
}
Components[name] = componentClass
return componentClass
end