模块:Basic

Stapx Steve讨论 | 贡献2020年8月26日 (三) 11:46的版本 (创建页面,内容为“--Basic By Stapx Steve --本模块包含一些基础的功能 local p = {} --p代表一个包(package) -- 以下是实战函数 -------------------------------…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

Icon-product.png
底层模块
它提供了支柱功能,请讨论后修改。


这是个基础模块,曾经用了个很新手的名字:Hello Lua,但这也确实是我首次使用 Lua 这门语言 ——

下面是这个基础模块的功能列表和详细用法。

实战函数

这些函数已经完善并且可以正常使用。

函数名 简介 参数 返回值 备注
getURL() 获取当前界面的 URL - 对应的无主域名编码 URL -
strCat(string, string) 连接两个字符串 两个字符串参数 连接完成的一个字符串 -
getStat(string) 获取站点统计信息 统计的类型,参见 mw.site.stats 统计数值 -
gethitokoto() 获取一言 是否显示from(一言出处),默认false 一言字符串 -
drawSector(int) 生成一个二值扇形图 主值数值(度数) 扇形图的完整 HTML 请确保输入合法

getURL()

获取当前界面的 URL。

{{#invoke:Basic|getURL}}
/%E6%A8%A1%E5%9D%97:Basic

srtCat()

连接两个字符串。

{{#invoke:Basic|strCat|This is the text| and add text}}
This is the text and add text

getStat()

获取站点统计信息

{{#invoke:Basic|getStat|articles}}
DHW PCS WIKI 目前总文章数:49

gethitokoto()

获取一言( https://hitokoto.cn

{{#invoke:Basic|gethitokoto|true}}
最最好的,与最最痛苦的,是一样的。 —— 文学与少女

drawSector()

生成一个二值扇形图

{{#invoke:Basic|drawSector|70}}
脚本错误:函数“drawSector”不存在。

计划函数

这些函数正在制作中,暂时无法使用但是已经存在计划。

学习函数

这些函数没有使用意义,仅仅是我用来学习 Lua 和 Mediawiki 的。

函数名 简介 参数 返回值 备注
hello() 输出 Hello, Lua! - - -
inPut(frame) 输出获取到的第一个参数 随意参数 - -
nowPage() 获取当前界面标题 - - -
Hello, Lua!
inPut1
模块:Basic

--Basic By Stapx Steve
--本模块包含一些基础的功能

local p = {} --p代表一个包(package)

-- 以下是实战函数
------------------------------------------------------------
function p.getURL()
	local urlobj = mw.uri.localUrl( mw.title.getCurrentTitle().fullText )
	return urlobj.path
end
function p.strCat(strs)
	return strs.args[1] .. strs.args[2]
end
function p.getStat( type )
	local info = mw.site.stats
	if( type.args[1] == "pages" )
	then
		return info.pages
	elseif( type.args[1] == "articles" )
	then
		return info.articles
	elseif( type.args[1] == "files" )
	then
		return info.files
	elseif( type.args[1] == "edits" )
	then
		return info.edits
	elseif( type.args[1] == "users" )
	then
		return info.users
	elseif( type.args[1] == "activeUsers" )
	then
		return info.activeUsers
	elseif( type.args[1] == "admins" )
	then
		return info.admins
	else 
		return "err - 类型不存在"
	end
end
function p.gethitokoto(sets)
	local yy = mw.ext.externaldata.getWebData {
    	url = "https://v1.hitokoto.cn"
		, data = "hit=$.hitokoto, from=$.from"
		, format = "json"
		, 'use jsonpath'
	}
	if(sets.args[1] == "true")
	then
		return yy.hit .. ' —— ' .. yy.from
	else
		return yy.hit
	end
end

-- 以下是计划函数
-----------------------------------------------------------

-- 以下是辅助函数
-----------------------------------------------------------

-- 以下是学习函数
-----------------------------------------------------------
function p.hello()
    return "Hello, Lua!"
end
function p.inPut( frame )
	local args = frame.args
	return args[1]
end
function p.nowPage()
	return mw.title.getCurrentTitle()
end

return p