summaryrefslogtreecommitdiff
path: root/server/src/emmy
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/emmy')
-rw-r--r--server/src/emmy/class.lua11
-rw-r--r--server/src/emmy/manager.lua26
-rw-r--r--server/src/emmy/type.lua41
3 files changed, 75 insertions, 3 deletions
diff --git a/server/src/emmy/class.lua b/server/src/emmy/class.lua
index f1101e91..5e87181d 100644
--- a/server/src/emmy/class.lua
+++ b/server/src/emmy/class.lua
@@ -16,11 +16,20 @@ function mt:getSource()
return listMgr.get(self.source)
end
-return function (source)
+function mt:setValue(value)
+ self.value = value
+end
+
+function mt:getValue()
+ return self.value
+end
+
+return function (manager, source)
local self = setmetatable({
name = source[1][1],
source = source.id,
extends = source[2] and source[2][1],
+ _manager = manager,
}, mt)
return self
end
diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua
index 99b46420..a3de42df 100644
--- a/server/src/emmy/manager.lua
+++ b/server/src/emmy/manager.lua
@@ -1,5 +1,6 @@
local listMgr = require 'vm.list'
local newClass = require 'emmy.class'
+local newType = require 'emmy.type'
local mt = {}
mt.__index = mt
@@ -26,7 +27,7 @@ function mt:flushClass(name)
list.version = version
end
-function mt:eachClass(name, callback)
+function mt:eachClassByName(name, callback)
self:flushClass(name)
local list = self._class[name]
if not list then
@@ -42,6 +43,22 @@ function mt:eachClass(name, callback)
end
end
+function mt:eachClass(...)
+ local n = select('#', ...)
+ if n == 1 then
+ local callback = ...
+ for name in pairs(self._class) do
+ local res = self:eachClassByName(name, callback)
+ if res ~= nil then
+ return res
+ end
+ end
+ else
+ local name, callback = ...
+ return self:eachClassByName(name, callback)
+ end
+end
+
function mt:addClass(source)
local className = source[1][1]
self:flushClass(className)
@@ -53,14 +70,19 @@ function mt:addClass(source)
}
self._class[className] = list
end
- list[source.id] = newClass(source)
+ list[source.id] = newClass(self, source)
return list[source.id]
end
+function mt:createType(source)
+ return newType(self, source)
+end
+
function mt:remove()
end
return function ()
+ ---@class emmyMgr
local self = setmetatable({
_class = {},
}, mt)
diff --git a/server/src/emmy/type.lua b/server/src/emmy/type.lua
new file mode 100644
index 00000000..c2195810
--- /dev/null
+++ b/server/src/emmy/type.lua
@@ -0,0 +1,41 @@
+local listMgr = require 'vm.list'
+
+local function buildName(source)
+ local names = {}
+ for i, type in ipairs(source) do
+ names[i] = type[1]
+ end
+ return table.concat(names, '|')
+end
+
+local mt = {}
+mt.__index = mt
+mt.type = 'emmy.type'
+
+function mt:getType()
+ return self.name
+end
+
+function mt:getName()
+ return self.name
+end
+
+function mt:getSource()
+ return listMgr.get(self.source)
+end
+
+function mt:getClass()
+ local class = self._manager:eachClass(self.name, function (class)
+ return class
+ end)
+ return class
+end
+
+return function (manager, source)
+ local self = setmetatable({
+ name = buildName(source),
+ source = source.id,
+ _manager = manager,
+ }, mt)
+ return self
+end