模块:Static/doc:修订间差异
来自星砂岛百科
更多语言
更多操作
创建页面 |
同步更新物品导航框 |
||
| 第1行: | 第1行: | ||
== 概述 == | == 概述 == | ||
'''Static''' 返回一个页面级共享表,用于在同一页面内的多次 <code><nowiki>#invoke</nowiki></code> 或 <code><nowiki>require</nowiki></code> 调用之间共享静态状态。 | |||
== | == 用法 == | ||
<syntaxhighlight lang= | <syntaxhighlight lang="lua"> | ||
local | local static = require('Module:Static') | ||
static.Example = static.Example or {} | |||
static.Example.count = (static.Example.count or 0) + 1 | |||
return static.Example.count | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== 示例 == | |||
<syntaxhighlight lang="lua"> | |||
local static = require('Module:Static') | |||
static._global = static._global or {} | |||
static._global.sample = 'ok' | |||
return static._global.sample | |||
static. | |||
static. | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== 注意事项 == | |||
* | * 默认应在各模块自己的子表下保存状态,避免互相污染。 | ||
* | * 只有明确需要跨模块共享时,才使用 <code><nowiki>_global</nowiki></code> 这样的公共命名空间。 | ||
* | * 该模块本身不提供 <code><nowiki>#invoke</nowiki></code> 入口,建议通过 <code><nowiki>require('Module:Static')</nowiki></code> 使用。 | ||
[[分类:元模块]] | |||
[[ | |||
2026年4月2日 (四) 15:06的最新版本
概述
Static 返回一个页面级共享表,用于在同一页面内的多次 #invoke 或 require 调用之间共享静态状态。
用法
local static = require('Module:Static')
static.Example = static.Example or {}
static.Example.count = (static.Example.count or 0) + 1
return static.Example.count
示例
local static = require('Module:Static')
static._global = static._global or {}
static._global.sample = 'ok'
return static._global.sample
注意事项
- 默认应在各模块自己的子表下保存状态,避免互相污染。
- 只有明确需要跨模块共享时,才使用
_global这样的公共命名空间。 - 该模块本身不提供
#invoke入口,建议通过require('Module:Static')使用。