mirror of
https://github.com/Keyslam-Group/Concord.git
synced 2025-09-01 20:03:55 -04:00
Allow named worlds
This commit is contained in:
parent
d4efca976c
commit
d0e227485e
6 changed files with 50 additions and 7 deletions
29
src/worlds.lua
Normal file
29
src/worlds.lua
Normal file
|
@ -0,0 +1,29 @@
|
|||
-- Worlds
|
||||
|
||||
local PATH = (...):gsub('%.[^%.]+$', '')
|
||||
|
||||
local Type = require(PATH..".type")
|
||||
|
||||
local Worlds = {}
|
||||
|
||||
function Worlds.register(name, world)
|
||||
if (type(name) ~= "string") then
|
||||
error("bad argument #1 to 'Worlds.register' (string expected, got "..type(name)..")", 3)
|
||||
end
|
||||
|
||||
if (not Type.isWorld(world)) then
|
||||
error("bad argument #2 to 'Worlds.register' (world expected, got "..type(world)..")", 3)
|
||||
end
|
||||
|
||||
if (rawget(Worlds, name)) then
|
||||
error("bad argument #2 to 'Worlds.register' (World with name '"..name.."' is already registerd)", 3)
|
||||
end
|
||||
|
||||
Worlds[name] = component
|
||||
end
|
||||
|
||||
return setmetatable(Worlds, {
|
||||
__index = function(_, name)
|
||||
error("Attempt to index world '"..tostring(name).."' that does not exist / was not registered", 2)
|
||||
end
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue