请输入您要查询的百科知识:

 

词条 Module:Sandbox/RexxS/ScanParms
释义 -- Test module to demo scanning of unknown parameters-- May be two parameters, representing url and text or just the url-- Parameters may be unnamed or specifically set as 1 and 2-- Problem arises when an unnamed parameter includes =

local p = {}

p.scan = function(frame)

if not frame:getParent().args then

return nil -- or return "No arguments" if debugging

end

local keys = {}

local vals = {}

local url

local text

local ctr = 0

-- scan the parameters passed to see if they contain a period

for k, v in pairs(frame:getParent().args) do

k = tostring(k)

if k:find(".", 1, true) then

-- the parameter name has a . in it, so probably like www.xyz.com?a=n

-- reconstruct parameter and set name to k1 or k2

ctr = ctr + 1

vals[#vals+1] = k .. "=" .. v

keys[#keys+1] = "k" .. ctr

else

vals[#vals+1] = v

keys[#keys+1] = k

end

end

-- now sort out which is url and which is text

if #keys == 0 then

return nil -- or "No parameters passed" if debugging

elseif #keys == 1 then

-- just a url supplied

url = vals[1]

text = vals[1]

elseif ctr > 1 then

-- more than one parameter name contained a period, so one is url, other is text

url = vals[2]

text = vals[1]

elseif ctr == 1 then

-- just one parameter name contained a period, so that's the url

if keys[1] == "k1" then

-- it was the first one

url = vals[1]

text = vals[2]

else

-- it was the second one

url = vals[2]

text = vals[1]

end

else

-- either no parameter name had colons or there's more than 2 parameters

-- so bail out with a reasonable default

url = vals[1]

text = vals[2]

end

return "url=" .. url .. " -- text=" .. text

end

return p

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/13 14:00:49