From b57a99b5e39288e66e0bc20334f8dc0bb582965d Mon Sep 17 00:00:00 2001 From: ralu Date: Fri, 8 Oct 2021 12:59:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84Module=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/Module/LegacyModule.lua | 4 +- libs/Module/ModuleSystem.lua | 87 ------------------------------------ 2 files changed, 2 insertions(+), 89 deletions(-) diff --git a/libs/Module/LegacyModule.lua b/libs/Module/LegacyModule.lua index 70d2409..88ad0d4 100644 --- a/libs/Module/LegacyModule.lua +++ b/libs/Module/LegacyModule.lua @@ -82,9 +82,9 @@ function LegacyModule:createDelegate() return end self['_t_' .. key] = fn; - self:regCallback(key, function(...) + regGlobalEvent(key, function(...) return self:callInCtx(fn, ...); - end) + end, self.name) elseif type(fn) == 'function' then self:regCallback(key, fn); end diff --git a/libs/Module/ModuleSystem.lua b/libs/Module/ModuleSystem.lua index 1d7a1c8..b587476 100644 --- a/libs/Module/ModuleSystem.lua +++ b/libs/Module/ModuleSystem.lua @@ -25,93 +25,6 @@ end ---@field simpleModule boolean 是否兼容老的luaModule ---@field absolutePath boolean ---[[ ----解决兼容普通lua的问题 -local function forSimpleModule() - local callInCtx; - local function loadFile(file, cb) - if file then - local moduleName; - for i, v in pairs(Modules) do - if v.___aPath == file then - moduleName = i; - end - end - loadModule(moduleName or file, { path = file, simpleModule = true, forceReload = true, absolutePath = true }); - end - local key = '__callInCtx' .. cb; - _G[key] = Func.bind(callInCtx, cb); - return key; - end - local simpleModuleCtx = { - string = {}, - table = {}, - VaildChar = Char.IsValidCharIndex, - NL = { - CreateNpc = function(file, cb) - return NL.CreateNpc(nil, loadFile(file, cb)); - end - }, - Char = {}, - Battle = {}, - }; - - callInCtx = function(name, ...) - return simpleModuleCtx[name](...) - end - - for f, n in pairs({ Char = Char, Battle = Battle }) do - for i, v in pairs(n) do - if string.sub(i, 1, 3) == 'Set' and string.sub(i, #i - 4) == 'Event' then - simpleModuleCtx[f][i] = function(file, cb, ...) - return v(nil, loadFile(file, cb), ...) - end - end - end - end - - for i, v in pairs(NL) do - if string.sub(i, 1, 3) == 'Reg' then - simpleModuleCtx.NL[i] = function(file, cb, ...) - return v(nil, loadFile(file, cb), ...) - end - end - end - - simpleModuleCtx.string = setmetatable(simpleModuleCtx.string, { __index = string }); - simpleModuleCtx.table = setmetatable(simpleModuleCtx.table, { __index = table }); - simpleModuleCtx.NL = setmetatable(simpleModuleCtx.NL, { __index = NL }); - simpleModuleCtx.Char = setmetatable(simpleModuleCtx.Char, { __index = Char }); - simpleModuleCtx.Battle = setmetatable(simpleModuleCtx.Battle, { __index = Battle }); - print(simpleModuleCtx.NL, simpleModuleCtx.NL.CreateNpc, NL, NL.CreateNpc) - local Delegate = {} - for k, _ff in pairs(NL) do - if string.sub(k, 1, 3) == 'Reg' then - Delegate['RegDel' .. string.sub(k, 4)] = function(fn) - if type(fn) == 'string' then - if simpleModuleCtx['__delegate_tmp_' .. fn] then - return - end - simpleModuleCtx['__delegate_tmp_' .. fn] = function(...) - if simpleModuleCtx[fn] then - return simpleModuleCtx[fn](...); - end - end - regGlobalEvent(string.sub(k, 4), simpleModuleCtx['__delegate_tmp_' .. fn], 'Delegate') - elseif type(fn) == 'function' then - regGlobalEvent(string.sub(k, 4), fn, 'Delegate'); - end - end - Delegate['Reg' .. string.sub(k, 4)] = Delegate['RegDel' .. string.sub(k, 4)]; - end - end - simpleModuleCtx.Delegate = Delegate; - return simpleModuleCtx; -end - -local simpleModuleCtx = forSimpleModule(); -]] - local function loadModuleFile(path, moduleName, forceReload) local ctx = {} local rG = {