mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-02 12:24:11 -04:00
Allow for named components
This commit is contained in:
parent
f7e1be8e1d
commit
bc47eaa651
2 changed files with 53 additions and 1 deletions
|
@ -6,8 +6,21 @@ Component.__index = Component
|
|||
--- Creates a new Component.
|
||||
-- @param populate A function that populates the Bag with values
|
||||
-- @return A Component object
|
||||
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 not (populate == nil or type(populate) == "function") then
|
||||
error("bad argument #2 to 'Component.new' (function/nil expected, got "..type(populate)..")", 2)
|
||||
end
|
||||
|
||||
if (Component[name] ~= nil) then
|
||||
error("bad argument #2 to 'Component.new' (Component with name '"..name.."' already exists", 2)
|
||||
end
|
||||
|
||||
local component = setmetatable({
|
||||
__name = name,
|
||||
__populate = populate,
|
||||
|
||||
__isComponent = true,
|
||||
|
@ -15,6 +28,8 @@ function Component.new(populate)
|
|||
|
||||
component.__mt = {__index = component}
|
||||
|
||||
Component[name] = component
|
||||
|
||||
return component
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue