Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/RexxS/ScanParms
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-- 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
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/RexxS/ScanParms/doc
(
edit
)