-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
用法如下: /* 加载模块 */ load-lib storage; /* 存储数据 */ storage.Save my-data {myvar1;myvar2;myvar3}; /* 提取数据 */ storage.Load my-data {myvar1;myvar2;myvar3}; 数据以 tintin++ 格式默认储存在 data 目录,文件名就是 Save/Load 的第一个参数。 存储位置支持文件重定位,即:如果储存时存在 var/data 目录,则改为储存到 var/data 目录。 如果提取时存在 var/data/my-data.tin 文件中,则改为从该文件获取内容。 用途举例:pp 大米可以通过 storage 来加载和存储黑白名单,优化 pp 大米的利用率。
- Loading branch information
Showing
3 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ out[1-9] | |
|
||
var/* | ||
var | ||
|
||
data/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#nop vim: set filetype=tt:; | ||
|
||
/* | ||
本文件属于 PaoTin++ 的一部分。 | ||
PaoTin++ © 2020~2022 的所有版权均由担子炮(dzp <[email protected]>) 享有并保留一切法律权利 | ||
你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。 | ||
*/ | ||
|
||
#var lib_storage[META] { | ||
{NAME} {通用存储引擎} | ||
{DESC} {可以存储和载入变量,这允许其它模块可以持久化自己的数据} | ||
{AUTHOR} {担子炮} | ||
}; | ||
|
||
#function {lib_storage.Init} { | ||
#local _ {@mkdir{data}}; | ||
#return {true}; | ||
}; | ||
|
||
#alias {storage.Save} { | ||
#local file {%1}; | ||
#local vars {%2}; | ||
|
||
#class comm-store-tmp open; | ||
#local var {}; | ||
#foreach {$vars} {var} { | ||
#var {dump-$var} {${$var}}; | ||
}; | ||
#class comm-store-tmp close; | ||
|
||
#local files {}; | ||
#line quiet #scan dir {var/data/} files; | ||
|
||
#if { &files[] > 0 } { | ||
#class comm-store-tmp write {var/data/${file}.tin}; | ||
}; | ||
#else { | ||
#class comm-store-tmp write {data/${file}.tin}; | ||
}; | ||
}; | ||
|
||
#alias {storage.Load} { | ||
#local file {%1}; | ||
#local vars {%2}; | ||
|
||
#line quiet #class comm-store-tmp {assign} {load-file data/${file}.tin}; | ||
#local var {}; | ||
#foreach {$vars} {var} { | ||
#var {$var} {${dump-$var}}; | ||
}; | ||
#class comm-store-tmp kill; | ||
}; |