打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

本站正在进行早期测试,目前仍存在许多内容的缺失。

模块:Common/doc

来自星砂岛百科

这是模块:Common的文档页面

概述

Common 提供中文百科 Lua 模块的基础通用能力,包括参数读取、JSON 数据页加载、文件存在判断和 LuaCache 辅助。

用法

local common = require('Module:Common')

local title = common.getCurrentTitleText()
local data = common.loadJsonData('数据:Item/item_mapping.json')
local key = common.normalizeKey(title)

示例

local common = require('Module:Common')

local cache_key = common.buildLuaCacheKey('demo', '1', 'example')
local cached = common.luaCacheGet(cache_key)
if cached == nil then
    cached = common.trim(' test ')
    common.luaCacheSet(cache_key, cached, 300)
end
return cached

函数

  • trim:去除首尾空白。
  • getArg:从 frame 与父级模板中读取参数。
  • toText:将布尔值、数组或普通值转成文本。
  • normalizeKey:统一键名格式。
  • loadJsonData:安全读取数据页 JSON。
  • getCurrentTitleText:返回当前页面标题。
  • filePageExists:判断文件页是否存在。
  • getFilePath:获取文件路径缓存值。
  • buildLuaCacheKeyluaCacheGetluaCacheSet:LuaCache 辅助函数。