| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486 |
- #nop vim: set filetype=tt:;
- /*
- 模块名称:模块加载器
- 模块说明:本文件属于框架代码的一部分,不建议修改。如有需求请在 GitHub 发 issue 或者 PR
- 版权声明:本文件属于 PaoTin++ 的一部分
- ===========
- PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
- 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
- ===========
- */
- load-file {framework/class.tin};
- class.open module-loader;
- #var xtt-modules {};
- #var xtt-modConfig {};
- #alias {LM} {load-module};
- #alias {load-module} {
- #local moduleName {%1};
- #local moduleConfig {%2};
- #if { "$moduleName" == "" } {
- warnLog 用法: load-module <模块全限定名称> <模块参数>;
- #return;
- };
- #nop 检查有没有加载成功。;
- #local prefix {$moduleName};
- #replace prefix {/} {_};
- #if { "${${prefix}-loaded}" == "true" } {
- infoLog 模块 $moduleName 已载入。;
- #if { "${xtt-modConfig[$moduleName][ENABLE]}" == "false" } {
- infoLog 但是该模块已经被禁用,如果你想要重新启用,请使用「<129>enable-module %1<299>」。;
- };
- #return;
- };
- #local path {};
- #foreach {$moduleName;$moduleName/__init__;$moduleName/__main__} {path} {
- class.open {load-module-$moduleName};
- #line sub var #action {^#READ {{plugins/($path)\.tin}}: FILE NOT FOUND.$} {
- class.kill {load-module-$moduleName};
- #var {${prefix}-loaded} {false};
- #line gag;
- };
- class.close {load-module-$moduleName};
- class.open module-loader;
- #var {${prefix}-loaded} {true};
- class.close module-loader;
- class.open {$moduleName};
- #var {${prefix}} {};
- class.close {$moduleName};
- #format path {plugins/%s.tin} {$path};
- #line local {
- #nop 模块名称;
- #local MODULE {$moduleName};
- #nop 模块路径;
- #local PATH {$path};
- #nop 模块中触发器的默认 ID;
- #local ID {%!{(?:|id=${moduleName})}};
- #nop 文本开始;
- #local {B} {^{[> ]*}};
- #nop 文本结束;
- #local {E} {%!{(?:|id=${moduleName})}$};
- #nop 颜色触发中的文本结束;
- #local {CE} {%!c$E};
- class.read {$moduleName} {$path};
- };
- #if { "${${prefix}-loaded}" == "true" } {
- class.kill {load-module-$moduleName};
- init-module {$moduleName} {$path} {$moduleConfig};
- #return;
- };
- };
- errLog 模块 $moduleName 加载失败。;
- #return;
- };
- #alias {init-module} {
- #local moduleName {%1};
- #local modulePath {%2};
- #local modConfig {%3};
- #local prefix {$moduleName};
- #replace prefix {/} {_};
- #nop 检查有没有加载成功。;
- #if { "${${prefix}-loaded}" != "true" } {
- #return;
- };
- #nop 检查有没有初始化过;
- #if { "${xtt-modules[$moduleName]}" != "" } {
- #return;
- };
- #local metaVarName {};
- #format metaVarName {%s[META]} {$prefix};
- #local metaInfo {
- ${$metaVarName}
- {PATH}{$modulePath}
- };
- #if { "${$metaVarName}" == "" } {
- #local metaInfo[TYPE] {弱模块};
- };
- #elseif @existsAlias{${moduleName}.Run} {
- #local metaInfo[TYPE] {纯模块};
- };
- #else {
- #local metaInfo[TYPE] {混合模块};
- };
- #var {xtt-modules[$moduleName]} {$metaInfo};
- #if { "$metaInfo[TYPE]" != "弱模块" } {
- #if { "$metaInfo[CONFIG]" != "" } {
- #foreach {*metaInfo[CONFIG][]} {key} {
- class.open {$moduleName};
- #var ${prefix}[config][$key] {$modConfig[$key]};
- class.close {$moduleName};
- class.open module-loader;
- #var xtt-modConfig[$moduleName][$key] {$modConfig[$key]};
- class.close module-loader;
- };
- };
- #local initFunc {${prefix}.Init};
- #if @existsFunction{$initFunc} {
- class.open {$moduleName};
- #local ok @$initFunc{};
- class.close {$moduleName};
- #if { "$ok" == "false" } {
- errLog 模块 $moduleName 加载失败。;
- class.kill {$moduleName};
- #return;
- };
- };
- };
- okLog 模块 $moduleName 已初始化成功。;
- #if { "$metaInfo[TYPE]" == "纯模块" } {
- okLog 本模块是纯模块,请使用 ${moduleName}.Start/Stop 来控制启动停止。;
- #if { "${xtt-modConfig[$moduleName][ENABLE]}" == "" } {
- disable-module {$moduleName} {true};
- };
- make-starter {$moduleName} {$prefix};
- };
- };
- #alias {KM} {kill-module};
- #alias {kill-module} {
- #local moduleName {%1};
- #if { "$moduleName" == "" } {
- warnLog 用法: kill-module <模块全限定名称>;
- #return;
- };
- infoLog 卸载 $moduleName。;
- #local modules {};
- #foreach {*{xtt-modules[]}} {name} {
- #if { "$name" != "$moduleName" } {
- #format modules {%s%s} {$modules} {{$name}{${xtt-modules[$name]}}};
- };
- };
- #var {xtt-modules} {$modules};
- #unvar xtt.module-doc[$moduleName];
- #local prefix {$moduleName};
- #replace prefix {/} {_};
- #unvar {${prefix}-loaded};
- class.kill {$moduleName};
- };
- #alias {RLM} {reload-module};
- #alias {reload-module} {
- #local moduleName {%1};
- #if { "$moduleName" == "" } {
- warnLog 用法: reload-module <模块全限定名称>;
- #return;
- };
- kill-module {%1};
- load-module {%1} {%2};
- };
- #alias {DM} {disable-module};
- #alias {disable-module} {
- #local moduleName {%1};
- #local dontCallStop {%2};
- #if { "${xtt-modules[$moduleName][TYPE]}" == "纯模块" && "$dontCallStop" != "true" } {
- ${moduleName}.Stop;
- #return;
- };
- #if { "$moduleName" == "" } {
- warnLog 用法: disable-module <模块全限定名称>;
- #return;
- };
- #if { "${xtt-modules[$moduleName]}" == "" } {
- errLog 模块 $moduleName 尚未加载模块。;
- #return;
- };
- #if { "${xtt-modConfig[$moduleName][ENABLE]}" == "false" } {
- warnLog 模块 $moduleName 已经禁用。;
- #return;
- };
- #var {xtt-modConfig[$moduleName][ENABLE]} {false};
- class.disable {$moduleName};
- infoLog <129>模块 $moduleName 已经禁用。<299>;
- };
- #alias {EM} {enable-module};
- #alias {enable-module} {
- #local moduleName {%1};
- #local dontCallStart {%2};
- #if { "${xtt-modules[$moduleName][TYPE]}" == "纯模块" && "$dontCallStart" != "true" } {
- ${moduleName}.Start;
- #return;
- };
- #if { "$moduleName" == "" } {
- warnLog 用法: enable-module <模块全限定名称>;
- #return;
- };
- #if { "${xtt-modules[$moduleName]}" == "" } {
- errLog 模块 $moduleName 尚未加载模块。;
- #return;
- };
- #if { "${xtt-modConfig[$moduleName][ENABLE]}" == "true" } {
- warnLog 模块 $moduleName 已经启用。;
- #return;
- };
- #var {xtt-modConfig[$moduleName][ENABLE]} {true};
- class.enable {$moduleName};
- infoLog <129>模块 $moduleName 已经启用。<299>;
- };
- #nop 列出所有已加载模块以及它们的开关状态、配置参数;
- #alias {MODS} {list-modules};
- #alias {list-modules} {
- #local _ {%0};
- #local format { %c%-30s %-8s %-8s %-4s %-6s %-6s %s};
- #echo {%c%h} {cyan} { 已加载模块 -- 请用 MOD <模块名> 来查看详细内容 };
- #echo {$format} {cyan} {模块名称} {作者} {类型} {状态} {事件} {配置项} {说明};
- #echo {$format} {cyan} {------------} {-------} {-------} {----} {----} {----} {------------------------------------};
- #local name {};
- #local count {0};
- #foreach {*{xtt-modules[]}} {name} {
- #math count {$count + 1};
- #local metaInfo {${xtt-modules[$name]}};
- #local cnName {$metaInfo[NAME]};
- #local author {$metaInfo[AUTHOR]};
- #local type {$metaInfo[TYPE]};
- #local desc {$metaInfo[DESC]};
- #local config {$metaInfo[CONFIG]};
- #local enable {<129>开启<299>};
- #local hasConfig {有};
- #local hasEvents {无};
- #if { "$config" == "" } {
- #local hasConfig {无};
- };
- #local event {@fp.Filter{{$gValidEvent};{"VALUE[module]"=="$name"}}};
- #if { &event[] > 0 } {
- #local hasEvents {<169>&event[]个<299>};
- };
- #if { "$type" == "纯模块" } {
- #local type {<129>纯模块<299>};
- };
- #elseif { "$type" == "混合模块" } {
- #local type {<139>混合模块<299>};
- };
- #if { "${xtt-modConfig[$moduleName][ENABLE]}" == "false" } {
- #local enable {<119>禁用<299>};
- };
- #echo {$format} {white} {@genModuleLink{$name;MOD}} {$author} {$type} {$enable} {$hasEvents} {$hasConfig} {$desc};
- };
- #echo {%c%h} {cyan} { 共列出 $count 项模块信息 };
- };
- #nop 列出所有已加载模块以及它们的开关状态、配置参数;
- #alias {MOD} {look-module %0; #buffer end};
- #alias {look-module} {
- #local moduleName {%1};
- #local metaInfo {${xtt-modules[$moduleName]}};
- #local cnName {$metaInfo[NAME]};
- #local path {$metaInfo[PATH]};
- #local type {$metaInfo[TYPE]};
- #local enable {${xtt-modConfig[$moduleName][ENABLE]}};
- #local desc {$metaInfo[DESC]};
- #local author {$metaInfo[AUTHOR]};
- #local note {$metaInfo[NOTE]};
- #local config {$metaInfo[CONFIG]};
- #if { "$moduleName" == "" } {
- warnLog 用法: look-module <模块全限定名称>;
- #return;
- };
- #if { "${xtt-modules[$moduleName]}" == "" } {
- errLog 模块 $moduleName 尚未加载。;
- #return;
- };
- #if { "$enable" == "false" } {
- #local enable {<119>禁用<299>};
- };
- #else {
- #local enable {<129>开启<299>};
- };
- #local moduleLink {@genModuleLink{$moduleName;HELP}};
- #echo {%c%h} {cyan} { $moduleLink<269> };
- #echo {%s} { <269>名称:<299> $moduleLink <269>类型:<299> $type <269>状态:<299> $enable <269>作者:<299> $author};
- #echo {%s} { <269>脚本路径:<299> $path};
- #if { "$type" == "弱模块" } {
- #echo {%c%h} {cyan} { 更多信息仅纯模块可见 };
- #return;
- };
- #echo {%s} { <269>说明:<299> $desc};
- #echo {%s} { <269>备注:<299> $note};
- #if { "$type" == "纯模块" } {
- #echo {%s} { <269>接口:<299> 你可以通过 $moduleName\.Start/Stop 命令来启动/停止模块。};
- };
- #local format { %c%-20s %-20s %s};
- #local event {@fp.Filter{{$gValidEvent};{"VALUE[module]"=="$moduleName"}}};
- #if { &event[] > 0 } {
- #local name {};
- #echo {%s} { <269>提供事件列表:<299>};
- #echo {$format} {cyan} {事件名称} {事件类型} {说明};
- #echo {$format} {cyan} {--------------------} {--------------------} {------------------------------};
- #foreach {*event[]} {name} {
- #local type {$event[$name][type]};
- #local desc {$event[$name][desc]};
- #echo {$format} {light cyan} {$name} {$type} {$desc};
- };
- };
- #if { &config[] <= 0 } {
- #echo {%c%h} {cyan} {};
- #return;
- };
- #local count {0};
- #echo {%s} { <269>配置参数表:<299>};
- #echo {$format} {cyan} {配置项} {当前值} {作用};
- #echo {$format} {cyan} {--------------------} {--------------------} {------------------------------};
- #local key {};
- #foreach {*config[]} {key} {
- #math count {$count + 1};
- #local value ${xtt-modConfig[$moduleName][$key]};
- #local desc {$config[$key]};
- #local prefix {$moduleName};
- #replace prefix {/} {_};
- #echo {$format} {light cyan} {$key} {{$value}} {$desc};
- };
- #echo {%c%h} {cyan} { 共列出 $count 项配置信息 };
- };
- #alias {make-starter} {
- #local moduleName {%1};
- #local prefix {%2};
- class.open module-loader;
- #tab {%1.Start};
- #alias {%1.Start} {
- #if { "${xtt-modConfig[%1][ENABLE]}" == "false" } {
- enable-module {%1} {true};
- };
- #local config {%%0};
- #local metaInfo {${%2[META]}};
- #foreach {*metaInfo[config][]} {key} {
- class.open {%1};
- #format {%2[config][$key]} {%s} {$config[$key]};
- class.close {%1};
- };
- #format xtt-modConfig {%s%s} {${xtt-modConfig}} {{%1}{${%2[config]}}};
- class.do {%1} %1.Run;
- };
- #tab {%1.Stop};
- #alias {%1.Stop} {
- #local reason {%%1};
- #if { "$reason" == "" } {
- #format reason {人为操作};
- };
- infoLog <169>由于<139>$reason<169>,%1 模块停止运行。<299>;
- #if @existsAlias{%1.Pause} {
- %1.Pause;
- };
- #if { "${xtt-modConfig[%1][ENABLE]}" == "true" } {
- disable-module {%1} {true};
- };
- };
- class.close module-loader;
- };
- #alias {LL} {load-lib};
- #alias {load-lib} {load-module lib/%1};
- #alias {RLL} {reload-lib};
- #alias {reload-lib} {
- kill-module {lib/%1};
- load-lib {%1} {%2};
- };
- #nop 给出一个用于屏幕显示的模块名称。会自动根据是否有文档点亮 MSLP 链接;
- #func {genModuleLink} {
- #local {name} {%1};
- #local {cmd} {%2};
- #if { "$name" == "" } {
- #return {};
- };
- #if { &xtt-modules[$name][] == 0 } {
- #return {$name};
- };
- #local cnName {$xtt-modules[$name][NAME]};
- #if { "$cnName" != "" } {
- #local cnName { (<169>$cnName<299>)};
- };
- #if { "$cmd" != "{MOD|HELP}" } {
- #return {$name$cnName};
- };
- #if { "$cmd" == "HELP" && &xtt.module-doc[$name][] > 0 } {
- #local name {@mslp.Help{$name;$name}};
- #local name {<140>$name<299>$cnName};
- };
- #else {
- #local name {@mslp.Module{$name;$name}};
- #local name {<149>$name<299>$cnName};
- };
- #return {$name};
- };
- class.close module-loader;
|