Module:Sandbox/サンムル/Luaq/test
< Module:Sandbox | サンムル | Luaq
跳到导航
跳到搜索
local module = {} local getCode = require('Module:GetPageCode') require("Module:Luaq") local console = "" local function printcls() console = "" end local function println(...) local line = "" local count = select("#", ...) local flag = true for i = 1, count do if (flag) then flag = false else line = line .. "\t" end line = line .. tostring(select(i, ...)) end line = line .. "\n" console = console .. line end local function getFuncCode(code, func) local funcCode = "" local declare = "function module." .. func .. "(" -- 函数定义开始语句 local declare_len = mw.ustring.len(declare) local close = "end" -- 函数定义结束语句 for line in mw.text.gsplit(code, "\n", true) do if declare then -- 尚未找到函数定义开始语句。 if mw.ustring.len(line) >= declare_len + 1 and mw.ustring.sub(line, 1, declare_len) == declare then declare = nil -- 找到函数定义开始语句。 end elseif close then -- 尚未找到函数定义结束语句。 if line == close then close = nil -- 找到函数定义结束语句。 else if funcCode ~= "" then funcCode = funcCode .. "\n" end funcCode = funcCode .. mw.ustring.sub(line, 5) end end end if declare == nil and close == nil then return funcCode else return nil end end function module.select() local t = { 5, 4, 3, str = "string" , 2, 1} local q = luaq.asQuery(t) :select(function(i, k, v) return type(v) end) println("数据源:") for k, v in pairs(t) do println("key = "..k, "value = "..v) end println() println("查询结果:") for i, v in enum(q) do println(v) end end function module.main(frame) local args = frame.args local func = args["func"] if not func or not module[func] then error("错误的函数名") end local output = args["output"] or "console" if output == "console" then module[func]() return console elseif output == "code" then local code = getCode(frame:getTitle()) return getFuncCode(code, func) else return nil end end return module