From 04c3ce15f1515b11e43e4630888e323c6372b409 Mon Sep 17 00:00:00 2001 From: sumneko Date: Thu, 18 Apr 2019 11:42:45 +0800 Subject: emmy.class --- server/src/emmy/manager.lua | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 server/src/emmy/manager.lua (limited to 'server/src/emmy/manager.lua') diff --git a/server/src/emmy/manager.lua b/server/src/emmy/manager.lua new file mode 100644 index 00000000..5f83c9d1 --- /dev/null +++ b/server/src/emmy/manager.lua @@ -0,0 +1,62 @@ +local listMgr = require 'vm.list' +local newClass = require 'emmy.class' + +local mt = {} +mt.__index = mt +mt.__name = 'emmyMgr' + +function mt:flushClass(name) + local list = self._class[name] + if not list then + return + end + local version = listMgr.getVersion() + if version == list.version then + return + end + for srcId in pairs(list) do + if not listMgr.get(srcId) then + list[srcId] = nil + end + end + if not next(list) then + self._class[name] = nil + return + end + list.version = version +end + +function mt:eachClass(name, callback) + self:flushClass(name) + local list = self._class[name] + if not list then + return + end + for _, class in pairs(list) do + callback(class) + end +end + +function mt:addClass(class, parent) + local className = class[1] + local list = self._class[className] + local version = listMgr.getVersion() + if not list then + list = { + version = version, + } + self._class[className] = list + end + list[class.id] = newClass(class, parent) + self:flushClass(className) +end + +function mt:remove() +end + +return function () + local self = setmetatable({ + _class = {}, + }, mt) + return self +end -- cgit v1.2.3